下面是java代码
- @Test
-
- public void zUnionStore() {
-
- zSetOperations.add("zUnionStoreKey1", "one", 1);
-
- zSetOperations.add("zUnionStoreKey1", "two", 2);
-
- zSetOperations.add("zUnionStoreKey2", "one", 1);
-
- zSetOperations.add("zUnionStoreKey2", "two", 2);
-
- zSetOperations.add("zUnionStoreKey2", "three", 3);
-
- ZParams zParams = new ZParams();
-
- zParams.weightsByDouble(2, 3);
-
- zParams.aggregate(ZParams.Aggregate.SUM);
-
- jedis.zunionstore("zUnionStoreSumResult", zParams, "zUnionStoreKey1", "zUnionStoreKey2");
-
- //求最小值
-
- zParams.aggregate(ZParams.Aggregate.MIN);
-
- jedis.zunionstore("zUnionStoreMinResult", zParams, "zUnionStoreKey1", "zUnionStoreKey2");
-
- //求最大值
-
- zParams.aggregate(ZParams.Aggregate.MAX);
-
- jedis.zunionstore("zUnionStoreMaxResult", zParams, "zUnionStoreKey1", "zUnionStoreKey2");
-
- //spring
-
- zSetOperations.unionAndStore("zUnionStoreKey1", "zUnionStoreKey2", "zUnionStoreResult");
-
- printTuple("zUnionStoreSumResult", jedis.zrangeWithScores("zUnionStoreSumResult", 0, -1));
-
- printTuple("zUnionStoreMinResult", jedis.zrangeWithScores("zUnionStoreMinResult", 0, -1));
-
- printTuple("zUnionStoreMaxResult", jedis.zrangeWithScores("zUnionStoreMaxResult", 0, -1));
-
- printTuple("zUnionStoreResult", jedis.zrangeWithScores("zUnionStoreResult", 0, -1));
-
- }
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|