ZINTERSTORE command in redis

ZINTERSTORE destination numkeys key [key ...]

Intersects multiple sorted sets and stores the resulting sorted set in a new key

ZINTERSTORE command in redis computes the intersection of numkeys sorted sets given by the specified keys, and stores the result in the destination. 

RETURN VALUE:

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

Syntax:

ZINTERSTORE destination numkeys key [key ...]

Example 1: When the intersection is present

redis:6379> ZADD mykey 1 A 2 B 3 C 4 D 5 E
(integer) 5
redis:6379> ZADD mykey2 1 A 2 B 4 D
(integer) 3
redis:6379> ZINTERSTORE dstKey 2 mykey mykey2
(integer) 3

Output

3


Example 2: When the intersection is not present

redis:6379> ZADD mykey 1 A 2 B 3 C 4 D 5 E
(integer) 5
redis:6379> ZADD mykey1 10 AA 20 BB 30 CC 40 DD 50 EE
(integer) 5
redis:6379> ZINTERSTORE dstKey 2 mykey mykey1
(integer) 0

Output

0

No comments:

Post a Comment