您的位置:首页 > 数据库 > Redis

Redis命令-有序集合-zunionstore

2016-04-25 21:45 615 查看

 

原文

http://www.redis.io/commands/zunionstore

 

简介

Add multiple sorted sets and store the resulting sorted set in a new key.

 

计算多个有序集合的并集,并把结果有序集合存在到一个新的key。

 

语法

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

 

版本

Available since 2.0.0.

 

自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.

 

O(N)+O(M log(M)):N是输入有序集合的大小的总和,M是结果有序集合的元素的数量。

 

描述

Computes the union of numkeys sorted sets given by the specified keys, and stores the result in destination. It is mandatory to provide the number of input keys (numkeys) before passing the input keys and the other (optional) arguments.

 

计算指定的有序集合的并集,并把结果存储在有序集合destination。在输入key和其他可选参数之前,必须提供输入key的数量numkeys。

 

By default, the resulting score of an element is the sum of its scores in the sorted sets where it exists.

 

默认情况下,一个元素的结果分数是它存在的有序集合中它的分数的总和。

 

Using the WEIGHTS option, it is possible to specify a multiplication factor for each input sorted set. This means that the score of every element in every input sorted set is multiplied by this factor before being passed to the aggregation function. When WEIGHTS is not given, the multiplication factors default to 1.

 

使用WEIGHTS选项,可以为每个输入有序集合指定一个乘积因子。这意味着每个输入有序集合中每个元素的分数在传给聚合函数之前要先乘以这个因子。当没有指定WEIGHTS时,乘积因子的默认值是1。

 

With the AGGREGATE option, it is possible to specify how the results of the union are aggregated. This option defaults to SUM, where the score of an element is summed across the inputs where it exists. When this option is set to either MIN or MAX, the resulting set will contain the minimum or maximum score of an element across the inputs where it exists.

 

使用AGGREGATE选项,可以指定并集的结果如何被聚合。这个选项的默认值是SUM,元素的分数是所有它存在的有序集合的分数之和。当这个选项设置为MIN或MAX时,结果集合将包含元素的最小或最大分数。

 

If destination already exists, it is overwritten.

 

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

 

返回值

Integer reply: the number of elements in the resulting sorted set at destination.

 

Integer:结果有序集合中元素的数量。

 

例子

redis>  ZADD zset1 1 "one"
(integer) 1
redis>  ZADD zset1 2 "two"
(integer) 1
redis>  ZADD zset2 1 "one"
(integer) 1
redis>  ZADD zset2 2 "two"
(integer) 1
redis>  ZADD zset2 3 "three"
(integer) 1
redis>  ZUNIONSTORE out 2 zset1 zset2 WEIGHTS 2 3
(integer) 3
redis>  ZRANGE out 0 -1 WITHSCORES
1) "one"
2) "5"
3) "three"
4) "9"
5) "two"
6) "10"
redis>

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: