Search in sources :

Example 1 with ZParams

use of redis.clients.jedis.ZParams in project cachecloud by sohutv.

the class SortedSetCommandsTest method zintertoreParams.

@Test
public void zintertoreParams() {
    jedis.zadd("foo", 1, "a");
    jedis.zadd("foo", 2, "b");
    jedis.zadd("bar", 2, "a");
    ZParams params = new ZParams();
    params.weights(2, 2.5);
    params.aggregate(ZParams.Aggregate.SUM);
    long result = jedis.zinterstore("dst", params, "foo", "bar");
    assertEquals(1, result);
    Set<Tuple> expected = new LinkedHashSet<Tuple>();
    expected.add(new Tuple("a", new Double(7)));
    assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
    // Binary
    jedis.zadd(bfoo, 1, ba);
    jedis.zadd(bfoo, 2, bb);
    jedis.zadd(bbar, 2, ba);
    ZParams bparams = new ZParams();
    bparams.weights(2, 2.5);
    bparams.aggregate(ZParams.Aggregate.SUM);
    long bresult = jedis.zinterstore(SafeEncoder.encode("dst"), bparams, bfoo, bbar);
    assertEquals(1, bresult);
    Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
    bexpected.add(new Tuple(ba, new Double(7)));
    assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100));
}
Also used : ZParams(redis.clients.jedis.ZParams) LinkedHashSet(java.util.LinkedHashSet) Tuple(redis.clients.jedis.Tuple) Test(org.junit.Test)

Example 2 with ZParams

use of redis.clients.jedis.ZParams in project jedis by xetorthio.

the class SortedSetCommandsTest method zintertoreParams.

@Test
public void zintertoreParams() {
    jedis.zadd("foo", 1, "a");
    jedis.zadd("foo", 2, "b");
    jedis.zadd("bar", 2, "a");
    ZParams params = new ZParams();
    params.weights(2, 2.5);
    params.aggregate(ZParams.Aggregate.SUM);
    long result = jedis.zinterstore("dst", params, "foo", "bar");
    assertEquals(1, result);
    Set<Tuple> expected = new LinkedHashSet<Tuple>();
    expected.add(new Tuple("a", new Double(7)));
    assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
    // Binary
    jedis.zadd(bfoo, 1, ba);
    jedis.zadd(bfoo, 2, bb);
    jedis.zadd(bbar, 2, ba);
    ZParams bparams = new ZParams();
    bparams.weights(2, 2.5);
    bparams.aggregate(ZParams.Aggregate.SUM);
    long bresult = jedis.zinterstore(SafeEncoder.encode("dst"), bparams, bfoo, bbar);
    assertEquals(1, bresult);
    Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
    bexpected.add(new Tuple(ba, new Double(7)));
    assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100));
}
Also used : ZParams(redis.clients.jedis.ZParams) LinkedHashSet(java.util.LinkedHashSet) Tuple(redis.clients.jedis.Tuple) Test(org.junit.Test)

Example 3 with ZParams

use of redis.clients.jedis.ZParams in project cachecloud by sohutv.

the class SortedSetCommandsTest method zunionstoreParams.

@Test
public void zunionstoreParams() {
    jedis.zadd("foo", 1, "a");
    jedis.zadd("foo", 2, "b");
    jedis.zadd("bar", 2, "a");
    jedis.zadd("bar", 2, "b");
    ZParams params = new ZParams();
    params.weights(2, 2.5);
    params.aggregate(ZParams.Aggregate.SUM);
    long result = jedis.zunionstore("dst", params, "foo", "bar");
    assertEquals(2, result);
    Set<Tuple> expected = new LinkedHashSet<Tuple>();
    expected.add(new Tuple("b", new Double(9)));
    expected.add(new Tuple("a", new Double(7)));
    assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
    // Binary
    jedis.zadd(bfoo, 1, ba);
    jedis.zadd(bfoo, 2, bb);
    jedis.zadd(bbar, 2, ba);
    jedis.zadd(bbar, 2, bb);
    ZParams bparams = new ZParams();
    bparams.weights(2, 2.5);
    bparams.aggregate(ZParams.Aggregate.SUM);
    long bresult = jedis.zunionstore(SafeEncoder.encode("dst"), bparams, bfoo, bbar);
    assertEquals(2, bresult);
    Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
    bexpected.add(new Tuple(bb, new Double(9)));
    bexpected.add(new Tuple(ba, new Double(7)));
    assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100));
}
Also used : ZParams(redis.clients.jedis.ZParams) LinkedHashSet(java.util.LinkedHashSet) Tuple(redis.clients.jedis.Tuple) Test(org.junit.Test)

Example 4 with ZParams

use of redis.clients.jedis.ZParams in project jedis by xetorthio.

the class SortedSetCommandsTest method zunionstoreParams.

@Test
public void zunionstoreParams() {
    jedis.zadd("foo", 1, "a");
    jedis.zadd("foo", 2, "b");
    jedis.zadd("bar", 2, "a");
    jedis.zadd("bar", 2, "b");
    ZParams params = new ZParams();
    params.weights(2, 2.5);
    params.aggregate(ZParams.Aggregate.SUM);
    long result = jedis.zunionstore("dst", params, "foo", "bar");
    assertEquals(2, result);
    Set<Tuple> expected = new LinkedHashSet<Tuple>();
    expected.add(new Tuple("b", new Double(9)));
    expected.add(new Tuple("a", new Double(7)));
    assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
    // Binary
    jedis.zadd(bfoo, 1, ba);
    jedis.zadd(bfoo, 2, bb);
    jedis.zadd(bbar, 2, ba);
    jedis.zadd(bbar, 2, bb);
    ZParams bparams = new ZParams();
    bparams.weights(2, 2.5);
    bparams.aggregate(ZParams.Aggregate.SUM);
    long bresult = jedis.zunionstore(SafeEncoder.encode("dst"), bparams, bfoo, bbar);
    assertEquals(2, bresult);
    Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
    bexpected.add(new Tuple(bb, new Double(9)));
    bexpected.add(new Tuple(ba, new Double(7)));
    assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100));
}
Also used : ZParams(redis.clients.jedis.ZParams) LinkedHashSet(java.util.LinkedHashSet) Tuple(redis.clients.jedis.Tuple) Test(org.junit.Test)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)4 Test (org.junit.Test)4 Tuple (redis.clients.jedis.Tuple)4 ZParams (redis.clients.jedis.ZParams)4