ZUNIONSTORE

Syntax
ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight
  [weight ...]] [AGGREGATE <SUM | MIN | MAX>]
Available since:
2.0.0
Time complexity:
O(N)+O(M log(M)) with N being the sum of the sizes of the input sorted sets, and M being the number of elements in the resulting sorted set.
ACL categories:
@write, @sortedset, @slow,

计算由指定键给出的numkeys个有序集合的并集,并将结果存储在destination中。 在传递输入键和其他(可选)参数之前,必须提供输入键的数量(numkeys)。

默认情况下,元素的结果分数是它在存在的排序集合中的分数之和。

使用WEIGHTS选项,可以为每个输入的排序集指定一个乘法因子。 这意味着在传递给聚合函数之前,每个输入排序集中每个元素的分数都会乘以这个因子。 当未给出WEIGHTS时,乘法因子默认为1

使用AGGREGATE选项,可以指定如何聚合联合的结果。 此选项默认为SUM,其中元素的分数在它存在的输入中求和。 当此选项设置为MINMAX时,结果集将包含元素在它存在的输入中的最小或最大分数。

如果 destination 已经存在,它将被覆盖。

示例

ZADD zset1 1 "one" ZADD zset1 2 "two" ZADD zset2 1 "one" ZADD zset2 2 "two" ZADD zset2 3 "three" ZUNIONSTORE out 2 zset1 zset2 WEIGHTS 2 3 ZRANGE out 0 -1 WITHSCORES

RESP2/RESP3 回复

Integer reply: the number of elements in the resulting sorted set.
RATE THIS PAGE
Back to top ↑