Redis - Set Sinterstore Command



Redis SINTERSTORE command stores the elements in a set after intersection of all specified sets. Keys that do not exist are considered to be empty sets. With one of the keys being an empty set, the resulting set is also empty (since set intersection with an empty set always results in an empty set).

Return Value

Integer reply, the number of elements in the resulting set.

Syntax

Following is the basic syntax of Redis SINTERSTORE command.

redis 127.0.0.1:6379> SINTERSTORE DESTINATION_KEY KEY KEY1..KEYN

Example

redis 127.0.0.1:6379> SADD myset1 "hello" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset1 "foo" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset1 "bar" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset2 "hello" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset2 "world" 
(integer) 1 
redis 127.0.0.1:6379> SINTERSTORE myset myset1 myset2 
(integer) 1 
redis 127.0.0.1:6379> SMEMBERS myset 
1) "hello" 
redis_sets.htm
Advertisements