union

英 [ˈju:niən]   美 [ˈjunjən]  

n.同盟,联盟;协会,工会;联合,团结

adj.工会的

复数: unions

store

英 [stɔ:(r)]   美 [stɔr, stor]  

n.商店;贮存物;仓库;大量

v.贮存;(在计算机里)存储

第三人称单数: stores 复数: stores 现在分词: storing 过去式: stored 过去分词: stored

redis ZUNIONSTORE命令 语法

作用:计算给定的一个或多个有序集的并集,其中给定 key 的数量必须以 numkeys 参数指定,并将该并集(结果集)储存到 destination 。

默认情况下,结果集中某个成员的 score 值是所有给定集下该成员 score 值之 和 。

语法:ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]

可用版本:>= 2.0.0

时间复杂度:O(N)+O(M log(M)), N 为给定有序集基数的总和, M 为结果集的基数。

返回:保存到 destination 的结果集的基数。

redis ZUNIONSTORE命令 示例

redis> ZRANGE programmer 0 -1 WITHSCORES
1) "peter"
2) "2000"
3) "jack"
4) "3500"
5) "tom"
6) "5000"
redis> ZRANGE manager 0 -1 WITHSCORES
1) "herry"
2) "2000"
3) "mary"
4) "3500"
5) "bob"
6) "4000"
redis> ZUNIONSTORE salary 2 programmer manager WEIGHTS 1 3   # 公司决定加薪。。。除了程序员。。。
(integer) 6
redis> ZRANGE salary 0 -1 WITHSCORES
1) "peter"
2) "2000"
3) "jack"
4) "3500"
5) "tom"
6) "5000"
7) "herry"
8) "6000"
9) "mary"
10) "10500"
11) "bob"
12) "12000"