Redis Sets: SUNION
Redis SUNION Command
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.
Here are some common uses and scenarios for the "SUNION" command:
- Union Operation: Computes the union of multiple sets, returning a set containing all unique elements from the input sets.
- Data Aggregation: Useful for aggregating data from multiple sources or sets into a single result.
- Combining Results: Helps in combining results from different queries or operations to get a comprehensive view.
- Set Operations: Facilitates complex set operations in data analysis and manipulation tasks.
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"
Previous:
Redis Sets SREM
Next:
Redis Sets SUNIONSTORE
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics