Redis命令-有序集合-zinterstore

原文

http://redis.io/commands/zinterstore

简介

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

计算多个有序集合的交集,并存储到另一个有序集合。

语法

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

版本

Available since 2.0.0.

自2.0.0版本可用。

时间复杂度

Time complexity: O(N*K)+O(M*log(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.

O(N*K)+O(M*log(M)):N是最小的输入有序集合,K是输入有序集合的数量,M是结果有序集合中元素的数量。

描述

Computes the intersection 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的数量。

By default, the resulting score of an element is the sum of its scores in the sorted sets where it exists. Because intersection requires an element to be a member of every given sorted set, this results in the score of every element in the resulting sorted set to be equal to the number of input sorted sets.

默认情况下,一个元素的结果分数是所有这个元素存在的有序集合中分数的总和。因为交集要求一个元素是每个指定有序集合的成员,这造成结果有序集合中每个元素的分数等于输入有序集合的数量。

For a description of the WEIGHTS and AGGREGATE options, see ZUNIONSTORE.

对于WEIGHTS和AGGREGATE选项,查看ZUNIONSTORE命令。

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>  ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3
(integer) 2
redis>  ZRANGE out 0 -1 WITHSCORES
1) "one"
2) "5"
3) "two"
4) "10"
redis>

猜你喜欢

转载自gitzhangyl.iteye.com/blog/2289770