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 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 testRename() throws ExecutionException, InterruptedException {
   String key1 = "SOURCE_KEY";
   String key2 = "DEST_KEY";
   client.delete(key1, key2).get();
   client.set(key1, "OK").get();
   String reply = client.rename(key1, key2).get();
   assertEquals("OK", reply);
   long existed = client.exists(key1).get();
   assertEquals(0, existed);
   String cached = (String) client.get(key2).get();
   assertEquals("OK", cached);
   client.set(key1, "OK").get();
   long result = client.renameNx(key1, key2).get();
   assertEquals(0, result);
   client.delete(key2).get();
   result = client.renameNx(key1, key2).get();
   assertEquals(1, result);
   existed = client.exists(key1).get();
   assertEquals(0, existed);
   cached = (String) client.get(key2).get();
   assertEquals("OK", cached);
 }
  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);
  }
  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 testSet() throws ExecutionException, InterruptedException {
   String result = client.set("TEST_KEY2", "CACHED").get();
   assertEquals("OK", result);
   String strCached = (String) client.get("TEST_KEY2").get();
   assertEquals("CACHED", strCached);
 }