Java Examples for redis.clients.jedis.ZParams

The following java examples will help you to understand the usage of redis.clients.jedis.ZParams. These source code samples are taken from different open source projects.

Example 1
Project: jedis-namespace-master  File: NamespaceJedisTest.java View source code
@Test
public void shouldProperlyUnionTwoSortedSetsWithOptions() {
    namespaced.zadd("sort1", 1, "1");
    namespaced.zadd("sort1", 2, "2");
    namespaced.zadd("sort2", 2, "2");
    namespaced.zadd("sort2", 3, "3");
    namespaced.zadd("sort2", 4, "4");
    namespaced.zunionstore("union", new ZParams().weights(2, 1), "sort1", "sort2");
    assertEquals(asSet("2", "4", "3", "1"), namespaced.zrevrange("union", 0, -1));
}
Example 2
Project: spring-data-redis-master  File: JedisZSetCommands.java View source code
/*
	 * (non-Javadoc)
	 * @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], byte[][])
	 */
@Override
public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
    try {
        ZParams zparams = new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));
        if (isPipelined()) {
            pipeline(connection.newJedisResult(connection.getPipeline().zinterstore(destKey, zparams, sets)));
            return null;
        }
        if (isQueueing()) {
            transaction(connection.newJedisResult(connection.getTransaction().zinterstore(destKey, zparams, sets)));
            return null;
        }
        return connection.getJedis().zinterstore(destKey, zparams, sets);
    } catch (Exception ex) {
        throw convertJedisAccessException(ex);
    }
}
Example 3
Project: redis-pipeline-master  File: RedisPipelinedManager.java View source code
/*
     * (non-Javadoc)
     * 
     * @see dw.core.redis.provider.RedisProvider#zinterstore(dw.cache.provider.CacheKey, java.lang.String, redis.clients.jedis.ZParams,
     * java.lang.String[])
     */
@Override
public RedisValue<Long> zinterstore(final CacheKey cacheKey, final String dstkey, final ZParams params, final String... sets) {
    int len = params.getParams().size() + sets.length + 1;
    String[] actualParams = new String[len];
    actualParams[0] = dstkey;
    int i = 1;
    for (byte[] p : params.getParams()) {
        try {
            actualParams[i++] = new String(p, "UTF-8");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    for (String set : sets) {
        actualParams[i++] = set;
    }
    concat("zinterstore", actualParams);
    RedisValue<Long> valueImpl = new RedisValue<Long>();
    appendCommand(new PipelineCommand<Long>(valueImpl) {

        @Override
        public Response<Long> run() {
            return ((RedisValue<Long>) pipelineProvider.zinterstore(cacheKey, dstkey, params, sets)).getResponse();
        }
    });
    return valueImpl;
}
Example 4
Project: cachecloud-master  File: SortedSetCommandsTest.java View source code
@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));
}
Example 5
Project: jedis-master  File: SortedSetCommandsTest.java View source code
@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));
}
Example 6
Project: craft-atom-master  File: DefaultRedisTransaction.java View source code
private void zinterstoremax0(String destination, String... keys) {
    t.zinterstore(destination, new ZParams().aggregate(Aggregate.MAX), keys);
}