Redis Zinterstore Command
The Redis Zinterstore command computes the intersection of one or more sorted sets specified by the keys, with the number of keys specified by the numkeys parameter, and stores the result in a destination key.
By default, the score of a member in the resulting set is the sum of its scores in the respective sorted sets.
Syntax
The basic syntax of the redis Zinterstore command is as follows:
redis 127.0.0.1:6379> ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]
Available Versions
= 2.0.0
Return Value
The number of members saved in the destination set.
Example
# Sorted set mid_test
redis 127.0.0.1:6379> ZADD mid_test 70 "Li Lei"
(integer) 1
redis 127.0.0.1:6379> ZADD mid_test 70 "Han Meimei"
(integer) 1
redis 127.0.0.1:6379> ZADD mid_test 99.5 "Tom"
(integer) 1
# Another sorted set fin_test
redis 127.0.0.1:6379> ZADD fin_test 88 "Li Lei"
(integer) 1
redis 127.0.0.1:6379> ZADD fin_test 75 "Han Meimei"
(integer) 1
redis 127.0.0.1:6379> ZADD fin_test 99.5 "Tom"
(integer) 1
# Intersection
redis 127.0.0.1:6379> ZINTERSTORE sum_point 2 mid_test fin_test
(integer) 3
# Display all members and their scores in the sorted set
redis 127.0.0.1:6379> ZRANGE sum_point 0 -1 WITHSCORES
1) "Han Meimei"
2) "145"
3) "Li Lei"
4) "158"
5) "Tom"
6) "199"