SINTERSTORE command in redis

SINTERSTORE dstkey key1 key2 ... keyN

This commnad works exactly like SINTER but instead of being returned the resulting set is stored as dstkey.

TIME COMPLEXITY: O(N*M) worst case where N is the cardinality of the smallest set and M the number of sets

RETURN VALUE: Status code reply

Syntax:

SINTERSTORE dstkey key1 key2 ... keyN

Example 1: When the intersection contains some elements.

redis:6379> SADD key1 a b c d
(integer) 4
redis:6379> SADD key2 d f
(integer) 2
redis:6379> SADD key3 g h
(integer) 2
redis:6379> SINTERSTORE dstkey key1 key2
(integer) 1

Output

1


Example 2: When the intersection does not contain any element.

redis:6379> SADD key1 a b c d
(integer) 4
redis:6379> SADD key2 d f
(integer) 2
redis:6379> SADD key3 g h
(integer) 2
redis:6379> SINTERSTORE dstkey key1 key2 key3
(integer) 0

Output

0

No comments:

Post a Comment