@Test public void zinterstore() { redis.zadd("zset1", 1, "one"); redis.zadd("zset1", 2, "two"); redis.zadd("zset2", 1, "one"); redis.zadd("zset2", 2, "two"); redis.zadd("zset2", 3, "three"); this.redis.zinterstore(key, "zset1", "zset2"); Set<Tuple> set = this.redis.zrangeWithScores(key, 0, -1); // Json.print(set, "set"); Assert.assertEquals("one,two", StringUtils.join(RedisUtil.tupleToString(set), ",")); Assert.assertEquals("2.0,4.0", StringUtils.join(RedisUtil.tupleToScores(set), ",")); }
@Test public void zinterstore2() { redis.zadd("zset1", 1, "one"); redis.zadd("zset1", 2, "two"); redis.zadd("zset2", 1, "one"); redis.zadd("zset2", 2, "two"); redis.zadd("zset2", 3, "three"); ZParams params = new ZParams().aggregate(ZParams.Aggregate.SUM); params.weights(2, 3); this.redis.zinterstore(key, params, "zset1", "zset2"); Set<Tuple> set = this.redis.zrangeWithScores(key, 0, -1); // Json.print(set, "set"); Assert.assertEquals("one,two", StringUtils.join(RedisUtil.tupleToString(set), ",")); Assert.assertEquals("5.0,10.0", StringUtils.join(RedisUtil.tupleToScores(set), ",")); }