Sunday 12 April 2015

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

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

Computes the intersection of all sorted sets and store the result into destination. Weight and aggregate arguments are optional. If you don't specify weight and aggregate arguments, then the resulting score of an element is the sum of its scores in the sorted sets where it exists.

127.0.0.1:6379> zadd set1 2 India 1 America 3 Brazil 
(integer) 3 
127.0.0.1:6379> zadd set2 3 China 4 India 2 Japan 
(integer) 3 
127.0.0.1:6379> zadd set3 1 Italy 3 Nepal 2 America 4 India 
(integer) 4 
127.0.0.1:6379> zinterstore set4 3 set1 set2 set3 
(integer) 1 
127.0.0.1:6379> zrange set4 0 1 withscores 
1) "India" 
2) "10" 
 
WEIGHTS option is used to specify a multiplication factor for each input sorted set, The score of every element in every input sorted set is multiplied by this factor before being passed to the aggregation function. If you don't specify any WEIGHTS option, multiplication option is set to 1.

127.0.0.1:6379> zinterstore set5 3 set1 set2 set3 weights 1 2 3 
(integer) 1 
127.0.0.1:6379> zrange set4 0 1 withscores 
1) "India" 
2) "10" 
 
AGGREGATE argument defaults to SUM, where the score of an element is summed across the inputs where it exists.
If AGGREGATE argument set to MIN, then the resulting set will contain the minimum score of an element across the input sorted sets where it exists.
If AGGREGATE argument set to MAX, then the resulting set will contain the maximum score of an element across the input sorted sets where it exists.
127.0.0.1:6379> zinterstore set6 3 set1 set2 set3 weights 1 2 3 aggregate min 
(integer) 1 
127.0.0.1:6379> zrange set6 0 1 withscores 
1) "India" 
2) "2" 
127.0.0.1:6379> zinterstore set7 3 set1 set2 set3 weights 1 2 3 aggregate max 
(integer) 1 
127.0.0.1:6379> zrange set7 0 1 withscores 
1) "India" 
2) "12" 
127.0.0.1:6379> 

 

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment