コード例 #1
0
 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);
 }
コード例 #2
0
 public void testZrem() 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 reply = client.zrem(key, "two").get();
   assertEquals(1, reply);
   List<ZEntity<?>> entitys =
       client.zrangeByScoreWithScores(key, ZNumbers.MINIMUM, ZNumbers.MAXIMUM).get();
   assertEquals(2, entitys.size());
   assertEquals("one", entitys.get(0).member);
   assertEquals("three", entitys.get(1).member);
   assertEquals(1.0, entitys.get(0).score);
   assertEquals(3.0, entitys.get(1).score);
   client.delete(key).get();
   client.zadd(key, 1, "one").get();
   client.zadd(key, 2, "two").get();
   client.zadd(key, 3, "three").get();
   reply = client.zremRangeByRank(key, 0, 1).get();
   assertEquals(2, reply);
   entitys = client.zrangeByScoreWithScores(key, ZNumbers.MINIMUM, ZNumbers.MAXIMUM).get();
   assertEquals(1, entitys.size());
   assertEquals("three", entitys.get(0).member);
   assertEquals(3.0, entitys.get(0).score);
   client.delete(key).get();
   client.zadd(key, 1, "one").get();
   client.zadd(key, 2, "two").get();
   client.zadd(key, 3, "three").get();
   reply = client.zremRangeByScore(key, ZNumbers.MINIMUM, ZNumbers.excludeNumber(2)).get();
   assertEquals(1, reply);
   entitys = client.zrangeByScoreWithScores(key, ZNumbers.MINIMUM, ZNumbers.MAXIMUM).get();
   assertEquals(2, entitys.size());
   assertEquals("two", entitys.get(0).member);
   assertEquals("three", entitys.get(1).member);
   assertEquals(2.0, entitys.get(0).score);
   assertEquals(3.0, entitys.get(1).score);
 }
コード例 #3
0
  public void testZrevRangeByScore() 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();
    List<String> cached = (List<String>) client.zrevRange(key, 0, -1).get();
    assertEquals(3, cached.size());
    assertEquals("one", cached.get(2));
    assertEquals("two", cached.get(1));
    assertEquals("three", cached.get(0));

    cached =
        (List<String>)
            client
                .zrevRangeByScore(key, ZNumbers.includeNumber(2), ZNumbers.includeNumber(1))
                .get();
    assertEquals(2, cached.size());
    assertEquals("two", cached.get(0));
    assertEquals("one", cached.get(1));

    cached =
        (List<String>)
            client
                .zrevRangeByScore(key, ZNumbers.includeNumber(2), ZNumbers.includeNumber(1), 1, 1)
                .get();
    assertEquals(1, cached.size());
    //        assertEquals("one", cached.get(0));
    assertEquals("one", cached.get(0));

    cached =
        (List<String>)
            client
                .zrevRangeByScore(key, ZNumbers.excludeNumber(2), ZNumbers.includeNumber(1))
                .get();
    assertEquals(1, cached.size());
    assertEquals("one", cached.get(0));

    cached =
        (List<String>)
            client
                .zrevRangeByScore(key, ZNumbers.excludeNumber(2), ZNumbers.excludeNumber(1))
                .get();
    assertEquals(0, cached.size());

    List<ZEntity<?>> entitys =
        client
            .zrevRangeByScoreWithScores(key, ZNumbers.includeNumber(2), ZNumbers.includeNumber(1))
            .get();
    assertEquals(2, entitys.size());

    assertEquals("one", entitys.get(1).member);
    assertEquals("two", entitys.get(0).member);
    assertEquals(1.0, entitys.get(1).score);
    assertEquals(2.0, entitys.get(0).score);

    entitys =
        client
            .zrevRangeByScoreWithScores(
                key, ZNumbers.includeNumber(2), ZNumbers.includeNumber(1), 1, 1)
            .get();
    assertEquals(1, entitys.size());

    //        assertEquals("one", entitys.get(0).member);
    assertEquals("one", entitys.get(0).member);
    //        assertEquals(1.0, entitys.get(0).score);
    assertEquals(1.0, entitys.get(0).score);
  }