Redis – Set Sunionstore Command

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

Redis SUNIONSTORE command is used to store the members of the set resulting from the union of all the given sets. Keys that do not exist are considered to be empty sets.

Return Value

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

Syntax

Following is the basic syntax of Redis SUNIONSTORE command.

redis 127.0.0.1:6379> SUNIONSTORE DESTINATION KEY KEY1..KEYN

Example

redis 127.0.0.1:6379> SADD myset1 "hello" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset1 "world" 
(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 "bar" 
(integer) 1 
redis 127.0.0.1:6379> SUNIONSTORE myset myset1 myset2 
(integer) 1 
redis 127.0.0.1:6379> SMEMBERS myset 
1) "bar" 
2) "world" 
3) "hello" 
4) "foo"

Leave a Reply