sunionstore
SUNIONSTORE
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Store the union in a new set
Usage: sunionstore destination_key source_key1 source_key2.
The behavior is the same as SUNION, plus storing the result in destination_key.
myset1 = { A, B, C }
myset2 = { B, C, D }
SUNIONSTORE dest_key myset1 myset2 = { A, B, C, D }
Example
| Command> | sadd myset1 A B C |
| Result> | 3 |
| Command> | sadd myset2 B C D |
| Result> | 3 |
| Command> | sunionstore dest_key myset1 myset2 |
| Result> | 4 |
| Command> | smembers dest_key |
| Result> |
1) A 2) B 3) C 4) D |
Store the union of three sets
Usage: sunionstore dest_key key1 key2 key3.
myset1 = { A, B, C }
myset2 = { B, C, D }
myset3 = { C, E, F }
SUNIONSTORE dest_key myset1 myset2 myset3 = { A, B, C, D, E, F }
There is no limit on the number of source keys.
If the destination key already exists, its contents are overwritten with the new set.
Example
| Command> | sadd myset3 C E F |
| Result> | 3 |
| Command> | sunionstore dest_key myset1 myset2 myset3 |
| Result> | 6 |
| Command> | smembers dest_key |
| Result> |
1) A 2) B 3) C 4) D 5) E 6) F |
A source key may also be the destination
SUNIONSTORE myset1 myset1 myset2 myset3
The previous contents of myset1 are replaced with the result.
Example
| Command> | sunionstore myset1 myset1 myset2 myset3 |
| Result> | 6 |
| Command> | smembers myset1 |
| Result> |
1) A 2) B 3) C 4) D 5) E 6) F |
Syntax
SUNIONSTORE destination_key source_key [source_key ...]
- Available since version 1.0.0.
- Time complexity is O(N), where N is the total number of members in the given sets.
| Related commands | SINTERSTORE, SDIFFSTORE |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << SDIFF | SUNIONSTORE | SINTERSTORE >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
