w3resource

Redis Sets: SUNION

SUNION key1 [key2]

Redis SUNION command is used to get 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.

Syntax:

SUNION KEY KEY1..KEYN

Available since:

1.0.0.

Return Value:

Array reply, list with members of the resulting set.

Return Value Type:

Integer

Example: Redis SUNION : The Union of two sets

The usage sunion key1 key2. 

mycolor1 = {R G B} 

mycolor2 = {G B Y}

SUNION mycolor1 mycolor2 = {R G B Y}

G, B belongs in both the original set, is set for once in the union does not allow duplicate.

127.0.0.1:6379> SADD mycolor1 R G B
(integer) 3
127.0.0.1:6379> SADD mycolor2 G B Y
(integer) 3
127.0.0.1:6379> SUNION mycolor1 mycolor2
1) "G"
2) "B"
3) "Y"
4) "R"

Example: Redis SUNION : The Union of three sets

The usage sunion key1 key2. 

mycolor1 = {R G B} 

mycolor2 = {G B Y}

mycolor3 = {B O P}

SUNION mycolor1 mycolor2 mycolor3 = {R G B Y O P}

127.0.0.1:6379> SADD mycolor3 B O P
(integer) 3
127.0.0.1:6379> SUNION mycolor1 mycolor2 mycolor3
1) "Y"
2) "R"
3) "O"
4) "P"
5) "G"
6) "B"



Follow us on Facebook and Twitter for latest update.