English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

The Redis Zinterstore command

Redis Sorted Sets (sorted set)

The Redis Zinterstore command computes the intersection of one or more sorted sets, where the number of given keys must be specified by the numkeys parameter, and stores the resulting intersection (result set) in destination.

By default, the score value of a member in the result set is the sum of the score values of the member under all given 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 to the target result set.

Online Examples

# 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"

Redis Sorted Sets (sorted set)