コード例 #1
0
 public void testLpushAndIndex() throws ExecutionException, InterruptedException {
   String key = "LIST_PUSH_KEY2";
   client.delete(key);
   long reply = client.lpushx(key, "OK").get();
   assertEquals(0, reply);
   reply = client.lpush(key, "OK").get();
   assertEquals(1, reply);
   reply = client.lpush(key, "KO").get();
   assertEquals(2, reply);
   String cached = (String) client.lindex(key, 1).get();
   assertEquals("OK", cached);
   cached = (String) client.lindex(key, 0).get();
   assertEquals("KO", cached);
 }
コード例 #2
0
  public void testLrem() throws ExecutionException, InterruptedException {
    String key = "LIST_REM_KEY2";
    client.delete(key);
    long reply = client.lpush(key, "1", "1", "OK", "2", "2").get();
    assertEquals(5, reply);
    reply = client.lrem(key, 1, "2").get();
    assertEquals(1, reply);
    String cached = (String) client.lindex(key, 0).get();
    assertEquals("2", cached);

    reply = client.lrem(key, -2, "1").get();
    assertEquals(2, reply);
    cached = (String) client.lindex(key, 1).get();
    assertEquals("OK", cached);
  }
コード例 #3
0
 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);
 }
コード例 #4
0
  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);
  }
コード例 #5
0
  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);
  }