public void testHlen() throws ExecutionException, InterruptedException {
   String key = "HASH_KEYS_KEY2";
   client.delete(key);
   String field1 = "TEST_FIELD1";
   String field2 = "TEST_FIELD2";
   long reply = client.hset(key, field1, 1).get();
   assertEquals(1, reply);
   reply = client.hset(key, field2, 2).get();
   assertEquals(1, reply);
   long size = client.hlen(key).get();
   assertEquals(2, size);
   size = client.hlen("NONNsd2").get();
   assertEquals(0, size);
 }
 public void testHmget() throws ExecutionException, InterruptedException {
   String key = "HASH_HMGET_KEY2";
   client.delete(key);
   String field1 = "TEST_FIELD1";
   String field2 = "TEST_FIELD2";
   long reply = client.hset(key, field1, 1).get();
   assertEquals(1, reply);
   reply = client.hset(key, field2, 2).get();
   assertEquals(1, reply);
   List<Integer> cached = client.hmgetInt(key, new String[] {field1, field2, "dfd"}).get();
   assertEquals(3, cached.size());
   assertEquals(1, cached.get(0).intValue());
   assertEquals(2, cached.get(1).intValue());
   assertNull(cached.get(2));
 }
 public void testHgetAndHset() throws ExecutionException, InterruptedException {
   String key = "HASH_KEY";
   client.delete(key);
   String field = "TEST_FIELD";
   long reply = client.hset(key, field, "OK").get();
   assertEquals(1, reply);
   reply = client.hset(key, field, "KO").get();
   assertEquals(0, reply);
   String cached = (String) client.hget(key, field).get();
   assertEquals("KO", cached);
   reply = client.hset(key, field, 1.01).get();
   assertEquals(0, reply);
   double cachedDouble = client.hgetDouble(key, field).get();
   assertEquals(1.01, cachedDouble);
 }
  public void testHkeys() throws ExecutionException, InterruptedException {
    String key = "HASH_KEYS_KEY2";
    client.delete(key);
    String field1 = "TEST_FIELD1";
    String field2 = "TEST_FIELD2";
    long reply = client.hset(key, field1, 1).get();
    assertEquals(1, reply);
    reply = client.hset(key, field2, 2).get();
    assertEquals(1, reply);
    List<String> keys = client.hkeys(key).get();
    assertEquals(2, keys.size());
    assertEquals(field1, keys.get(0));
    assertEquals(field2, keys.get(1));

    keys = client.hkeys("NONNsd2").get();
    assertEquals(0, keys.size());
  }
 public void testHdelAndExists() throws ExecutionException, InterruptedException {
   String key = "HASH_KEY1";
   client.delete(key);
   String field1 = "TEST_FIELD1";
   String field2 = "TEST_FIELD2";
   long reply = client.hset(key, field1, "OK").get();
   assertEquals(1, reply);
   reply = client.hset(key, field2, "KO").get();
   assertEquals(1, reply);
   reply = client.hexists(key, field1).get();
   assertEquals(1, reply);
   reply = client.hexists(key, field2).get();
   assertEquals(1, reply);
   reply = client.hdel(key, field1, field2).get();
   assertEquals(2, reply);
   reply = client.hexists(key, field1).get();
   assertEquals(0, reply);
   reply = client.hexists(key, field2).get();
   assertEquals(0, reply);
 }
 public void testHincrBy() throws ExecutionException, InterruptedException {
   String key = "HASH_INCR_KEY2";
   client.delete(key);
   String field1 = "TEST_FIELD1";
   String field2 = "TEST_FIELD2";
   long reply = client.hset(key, field1, 1).get();
   assertEquals(1, reply);
   reply = client.hincrBy(key, field2, 1).get();
   assertEquals(1, reply);
   reply = client.hincrBy(key, field1, 1).get();
   assertEquals(2, reply);
   reply = client.hincrBy(key, field1, -3).get();
   assertEquals(-1, reply);
 }
  public void testHgetAll() throws ExecutionException, InterruptedException {
    String key = "HASH_KEY2";
    client.delete(key);
    String field1 = "TEST_FIELD1";
    String field2 = "TEST_FIELD2";
    long reply = client.hset(key, field1, "OK").get();
    assertEquals(1, reply);
    reply = client.hset(key, field2, "KO").get();
    assertEquals(1, reply);
    Map<String, Object> cached = (Map<String, Object>) client.hgetAll(key).get();
    assertEquals(2, cached.size());
    assertEquals("OK", cached.get(field1));
    assertEquals("KO", cached.get(field2));

    reply = client.hset(key, field1, 1).get();
    assertEquals(0, reply);
    reply = client.hset(key, field2, 2).get();
    assertEquals(0, reply);
    Map<String, Integer> cachedInt = client.hgetAllInt(key).get();
    assertEquals(2, cachedInt.size());
    assertEquals(1, cachedInt.get(field1).intValue());
    assertEquals(2, cachedInt.get(field2).intValue());
  }