public void testHvals() throws ExecutionException, InterruptedException {
    String key = "HASH_HVALS_KEY2";
    client.delete(key);
    String field1 = "TEST_FIELD1";
    String field2 = "TEST_FIELD2";
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put(field1, 1);
    map.put(field2, 2);
    String reply = client.hmsetInt(key, map).get();
    assertEquals("OK", reply);
    List<Integer> cached = client.hvalsInt(key).get();
    assertEquals(2, cached.size());
    //        assertEquals(1, cached.get(0).intValue());
    //        assertEquals(2, cached.get(1).intValue());

    Map<String, String> map2 = new HashMap<String, String>();
    map2.put(field1, "OK");
    map2.put(field2, "KO");
    reply = client.hmset(key, map2).get();
    assertEquals("OK", reply);
    List<String> cachedStr = (List<String>) client.hvals(key).get();
    assertEquals(2, cached.size());
    //        assertEquals("OK", cachedStr.get(0));
    //        assertEquals("KO", cachedStr.get(1));

  }
 public void testLlen() throws ExecutionException, InterruptedException {
   String key = "LIST_LEN_KEY2";
   client.delete(key);
   long reply = client.lpush(key, "KO", "OK").get();
   assertEquals(2, reply);
   reply = client.llen(key).get();
   assertEquals(2, reply);
 }
 public void testKeys() throws ExecutionException, InterruptedException {
   Map<String, String> map = new HashMap<String, String>();
   map.put("ONE_KEY1", "TES");
   map.put("ONE_KEY2", "EST");
   client.msetObject(map).get();
   List<String> keys = client.keys("ONE_*").get();
   assertEquals("ONE_KEY1", keys.get(0));
   assertEquals(2, keys.size());
 }
 public void testMset() throws ExecutionException, InterruptedException {
   Map<String, Integer> map = new HashMap<String, Integer>();
   map.put("MAP_KEY1", 1);
   map.put("MAP_KEY2", 2);
   String result = client.msetInt(map).get();
   assertEquals("OK", result);
   int cached = client.getInt("MAP_KEY1").get();
   assertEquals(1, cached);
 }
 public void testPresist() throws ExecutionException, InterruptedException {
   client.setEx("PRESIST_KEY", "OK", 10);
   long reply = client.ttl("PRESIST_KEY").get();
   assertEquals(10, reply);
   reply = client.presist("PRESIST_KEY").get();
   assertEquals(1, reply);
   reply = client.ttl("PRESIST_KEY").get();
   assertEquals(-1, reply);
 }
 public void testSisMember() throws ExecutionException, InterruptedException {
   String key = "SET_ADD_KEY2";
   client.delete(key).get();
   long reply = client.sadd(key, "OK", "KO").get();
   assertEquals(2, reply);
   reply = client.sisMember(key, "OK").get();
   assertEquals(1, reply);
   reply = client.sisMember(key, "OKO").get();
   assertEquals(0, reply);
 }
 public void testZIncrBy() throws ExecutionException, InterruptedException {
   String key = "ZSET_ADD_KEY2";
   client.delete(key).get();
   long reply = client.zadd(key, 1, "a").get();
   assertEquals(1, reply);
   double score = client.zincrBy(key, 1, "a").get();
   assertEquals(2.0, score);
   score = client.zscore(key, "a").get();
   assertEquals(2.0, score);
 }
 public void testZadd() throws ExecutionException, InterruptedException {
   String key = "ZSET_ADD_KEY1";
   client.delete(key).get();
   long reply = client.zadd(key, 1, "a").get();
   assertEquals(1, reply);
   reply = client.zadd(key, 2, "b", new ZEntity<String>("c", 3)).get();
   assertEquals(2, reply);
   reply = client.zcard(key).get();
   assertEquals(3, reply);
   reply = client.zcount(key, ZNumbers.MINIMUM, ZNumbers.MAXIMUM).get();
   assertEquals(3, reply);
   reply = client.zcount(key, ZNumbers.includeNumber(1), ZNumbers.MAXIMUM).get();
   assertEquals(3, reply);
   reply = client.zcount(key, ZNumbers.excludeNumber(1), ZNumbers.MAXIMUM).get();
   assertEquals(2, reply);
   List<String> cached = (List<String>) client.zrange(key, 0, 1).get();
   assertEquals(2, cached.size());
   assertEquals("a", cached.get(0));
   assertEquals("b", cached.get(1));
   List<ZEntity<?>> entitys = client.zrangeWithScores(key, 0, 1).get();
   assertEquals(2, entitys.size());
   assertEquals("a", entitys.get(0).member);
   assertEquals("b", entitys.get(1).member);
   assertEquals(1.0, entitys.get(0).score);
   assertEquals(2.0, entitys.get(1).score);
 }
  public void testSetLongAndDouble() throws ExecutionException, InterruptedException {
    String result = client.set("TEST_KEY_LONG", 1l).get();
    assertEquals("OK", result);
    long cached = client.getLong("TEST_KEY_LONG").get();
    assertEquals(1l, cached);

    result = client.set("TEST_KEY_DOUBLE", 1.013).get();
    assertEquals("OK", result);
    double cachedDouble = client.getDouble("TEST_KEY_DOUBLE").get();
    assertEquals(1.013, cachedDouble);
  }
 public void testZrank() throws ExecutionException, InterruptedException {
   String key = "ZSET";
   client.delete(key).get();
   client.zadd(key, 1, "one").get();
   client.zadd(key, 2, "two").get();
   client.zadd(key, 3, "three").get();
   long rank = client.zrank(key, "three").get();
   assertEquals(2, rank);
   rank = client.zrevRank(key, "three").get();
   assertEquals(0, rank);
 }
  public void testSetNx() throws ExecutionException, InterruptedException {
    String key1 = "NX_KEY1";
    client.delete(key1);
    long reply = client.setNx(key1, "sss").get();
    assertEquals(1, reply);

    reply = client.setNx(key1, 2).get();
    assertEquals(0, reply);

    String cached = (String) client.get(key1).get();
    assertEquals("sss", cached);
  }
 public void testSaddAndCardAndMembers() throws ExecutionException, InterruptedException {
   String key = "SET_ADD_KEY";
   client.delete(key).get();
   long reply = client.sadd(key, "OK", "KO").get();
   assertEquals(2, reply);
   reply = client.scard(key).get();
   assertEquals(2, reply);
   List<String> cached = (List<String>) client.smembers(key).get();
   assertEquals(2, cached.size());
   assertEquals("OK", cached.get(0));
   assertEquals("KO", cached.get(1));
 }
 public void testReconnect() throws ExecutionException, InterruptedException, TimeoutException {
   String key = "GET_KEY";
   client.set(key, "OK").get();
   client.closeForTest();
   try {
     client.get(key).get(1, TimeUnit.SECONDS);
   } catch (TimeoutException e) {
     assertTrue(true);
   }
   Thread.sleep(3000);
   String reply = (String) client.get(key).get();
   assertEquals("OK", reply);
 }
  public void testLtrim() throws ExecutionException, InterruptedException {
    String key = "LIST_TRIM_KEY2";
    client.delete(key);
    long reply = client.lpush(key, "1", "1", "OK", "2", "2").get();
    assertEquals(5, reply);
    String result = client.ltrim(key, 1, 3).get();

    assertEquals("OK", result);
    List<String> range = (List<String>) client.lrange(key, 0, -1).get();
    assertEquals(3, range.size());
    assertEquals("2", range.get(0));
    assertEquals("OK", range.get(1));
    assertEquals("1", range.get(2));
  }
 public void testZinterAndUnion() throws ExecutionException, InterruptedException {
   String key1 = "ZSET1";
   String key2 = "ZSET2";
   client.delete(key1, key2).get();
   client.zadd(key1, 1, "one");
   client.zadd(key1, 2, "two");
   client.zadd(key2, 1, "one");
   client.zadd(key2, 2, "two");
   client.zadd(key2, 3, "three");
   long reply = client.zinterStore("out", new String[] {key1, key2}, new int[] {2, 3}, null).get();
   assertEquals(2, reply);
   List<ZEntity<?>> entitys = client.zrangeWithScores("out", 0, -1).get();
   assertEquals(2, entitys.size());
   assertEquals("one", entitys.get(0).member);
   assertEquals("two", entitys.get(1).member);
   assertEquals(5.0, entitys.get(0).score);
   assertEquals(10.0, entitys.get(1).score);
   reply = client.zunionStore("out", new String[] {key1, key2}, new int[] {2, 3}, null).get();
   assertEquals(3, reply);
   entitys = client.zrangeWithScores("out", 0, -1).get();
   assertEquals(3, entitys.size());
   assertEquals("one", entitys.get(0).member);
   assertEquals("three", entitys.get(1).member);
   assertEquals("two", entitys.get(2).member);
   assertEquals(5.0, entitys.get(0).score);
   assertEquals(9.0, entitys.get(1).score);
   assertEquals(10.0, entitys.get(2).score);
 }
  public void testMsetnx() throws ExecutionException, InterruptedException {
    Map<String, String> map = new HashMap<String, String>();
    map.put("MAPNX_KEY1", "TES");
    map.put("MAPNX_KEY2", "EST");

    client.delete("MAPNX_KEY1", "MAPNX_KEY2");
    long reply = client.msetObjectNx(map).get();
    assertEquals(1, reply);

    client.delete("MAPNX_KEY1");

    reply = client.msetObjectNx(map).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 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 testLset() throws ExecutionException, InterruptedException {
    String key = "LIST_SET_KEY2";
    client.delete(key);
    long reply = client.lpush(key, "1", "1", "OK", "2", "2").get();
    assertEquals(5, reply);
    String result = client.lset(key, 1, "3").get();

    assertEquals("OK", result);
    String cached = (String) client.lindex(key, 1).get();
    assertEquals("3", cached);

    result = client.lset(key, 6, "3").get();

    assertEquals("ERR index out of range", result);
  }
  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 testMget() throws ExecutionException, InterruptedException {
   Map<String, String> map = new HashMap<String, String>();
   map.put("MAPMX_KEY1", "TES");
   map.put("MAPMX_KEY2", "EST");
   client.msetObjectNx(map).get();
   List<String> result =
       (List<String>) client.mget(new String[] {"MAPMX_KEY1", "MAPMX_KEY2", "NON_EXIST"}).get();
   assertEquals("TES", result.get(0));
   assertEquals("EST", result.get(1));
   assertEquals(null, result.get(2));
   Map<String, Integer> map2 = new HashMap<String, Integer>();
   map2.put("MAP_KEY1", 1);
   map2.put("MAP_KEY2", 2);
   String resultStr = client.msetInt(map2).get();
   assertEquals("OK", resultStr);
   List<Integer> cached = client.mgetInt(new String[] {"MAP_KEY1", "MAP_KEY2"}).get();
   assertEquals(2, cached.size());
   assertEquals(1, cached.get(0).intValue());
   assertEquals(2, cached.get(1).intValue());
 }
 public void testIncrAndDecr() throws ExecutionException, InterruptedException {
   String key = "NUMBER_KEY";
   client.delete(key).get();
   long reply = client.incr(key).get();
   assertEquals(1, reply);
   reply = client.getInt(key).get();
   assertEquals(1, reply);
   reply = client.incr(key).get();
   assertEquals(2, reply);
   reply = client.getInt(key).get();
   assertEquals(2, reply);
   reply = client.incrBy(key, 3).get();
   assertEquals(5, reply);
   reply = client.decrBy(key, 3).get();
   assertEquals(2, reply);
   reply = client.decrBy(key, 1).get();
   assertEquals(1, reply);
 }
 public void testLinsert() throws ExecutionException, InterruptedException {
   String key = "LIST_INSERT_KEY2";
   client.delete(key);
   long reply = client.lpush(key, "KO", "OK").get();
   assertEquals(2, reply);
   reply = client.linsertAfter(key, "OKO", "KOK").get();
   assertEquals(-1, reply);
   reply = client.linsertAfter(key, "OK", "KK").get();
   assertEquals(3, reply);
   String cached = (String) client.lindex(key, 1).get();
   assertEquals("KK", cached);
   reply = client.linsertBefore(key, "KK", "OO").get();
   assertEquals(4, reply);
   cached = (String) client.lindex(key, 1).get();
   assertEquals("OO", cached);
   cached = (String) client.lindex(key, 3).get();
   assertEquals("KO", cached);
 }
  public void testRpoplpush() throws ExecutionException, InterruptedException {
    String key1 = "LIST_RPUSH_KEY1";
    String key2 = "LIST_RPUSH_KEY2";
    client.delete(key1, key2);

    long reply = client.rpush(key1, "OK", "KO").get();
    assertEquals(2, reply);
    reply = client.rpush(key2, "1", "2").get();
    assertEquals(2, reply);
    String poped = (String) client.rpoplpush(key1, key2).get();
    assertEquals("KO", poped);
    reply = client.llen(key1).get();
    assertEquals(1, reply);
    reply = client.llen(key2).get();
    assertEquals(3, reply);
    poped = (String) client.lindex(key1, 0).get();
    assertEquals("OK", poped);
    poped = (String) client.lindex(key2, 0).get();
    assertEquals("KO", poped);
    poped = (String) client.rpoplpush("ssss", key2).get();
    assertEquals(null, poped);
  }
  public void testMultClient() throws ExecutionException, InterruptedException {
    NettyRedisClient client2 = new NettyRedisClient("127.0.0.1:6379", 0, null);
    String key = "MIGRATE_KEY";
    client.delete(key).get();
    client2.delete(key).get();
    client.set(key, "OK").get();
    client2.set(key, "OK").get();
    //        String reply = client.migrate("127.0.0.1", 6379, key, 0, 1000).get();
    //        assertEquals("OK", reply);
    long existed = client.exists(key).get();
    assertEquals(1, existed);

    String reply = (String) client2.get(key).get();
    assertEquals("OK", reply);
  }
 public void testGetAndSet() throws ExecutionException, InterruptedException {
   String key = "GETANDSET_KEY";
   client.delete(key).get();
   long reply = client.incr(key).get();
   assertEquals(1, reply);
   reply = client.getAndSet(key, 0).get();
   assertEquals(1, reply);
   reply = client.getInt(key).get();
   assertEquals(0, reply);
   client.set(key, "HEL");
   String replyStr = (String) client.getAndSet(key, "LLO").get();
   assertEquals("HEL", replyStr);
   replyStr = (String) client.get(key).get();
   assertEquals("LLO", replyStr);
 }
 public void testRpopAndPush() throws ExecutionException, InterruptedException {
   String key = "LIST_RPUSH_KEY2";
   client.delete(key);
   long reply = client.rpushx(key, "OK").get();
   assertEquals(0, reply);
   reply = client.rpush(key, "OK", "KO").get();
   assertEquals(2, reply);
   String cached = (String) client.rpop(key).get();
   assertEquals("KO", cached);
   cached = (String) client.rpop(key).get();
   assertEquals("OK", cached);
   cached = (String) client.rpop(key).get();
   assertEquals(null, cached);
   cached = (String) client.rpop("gfgr4").get();
   assertEquals(null, cached);
 }
 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 testDumpAndRestore()
      throws ExecutionException, InterruptedException, TimeoutException {
    String key = "DUMP_KEY";
    client.delete(key).get();
    client.set(key, "OK").get();
    byte[] dump = client.dump(key).get(1, TimeUnit.SECONDS);

    client.delete(key).get();
    String reply = client.restore(key, 0, dump).get();
    assertEquals("OK", reply);
    reply = (String) client.get(key).get();
    assertEquals("OK", reply);
  }