The Redis SUNION command returns the union of the specified sets. Keys that do not exist are considered to be empty sets.

Syntax

The basic syntax of the SUNION command is as follows:

1
SUNION key [key ...]

For example:

1
2
3
4
key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SUNION key1 key2 key3 = {a,b,c,d,e}

Available Since

Redis version >= 1.0.0

Time Complexity

O(N) where N is the total number of elements in all given sets.

ACL Categories

@read, @set, @slow

Return Value

Returns the members of the set resulting from the union of all the given sets.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
127.0.0.1:6379> SADD key1 a b c d
(integer) 4
127.0.0.1:6379> SADD key2 c
(integer) 1
127.0.0.1:6379> SADD key3 a c e
(integer) 3
127.0.0.1:6379> SUNION key1 key2 key3
1) "b"
2) "d"
3) "e"
4) "c"
5) "a"
127.0.0.1:6379>