sunion
SUNION
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Union of sets
Usage: sunion key1 key2.
myset1 = { A, B, C }
myset2 = { B, C, D }
SUNION myset1 myset2 = { A, B, C, D }
B and C belong to both sets. Because a set does not allow duplicates, each appears only once in the union.
Example
| Command> | sadd myset1 A B C |
| Result> | 3 |
| Command> | sadd myset2 B C D |
| Result> | 3 |
| Command> | sunion myset1 myset2 |
| Result> |
1) C 2) B Returned in no particular order. 3) A 4) D |
Union of three sets
Usage: sunion key1 key2 key3.
myset1 = { A, B, C }
myset2 = { B, C, D }
myset3 = { C, E, F }
SUNION myset1 myset2 myset3 = { A, B, C, D, E, F }
There is no limit on the number of keys.
Example
| Command> | sadd myset3 C E F |
| Result> | 3 |
| Command> | sunion myset1 myset2 myset3 |
| Result> |
1) D 2) B 3) A 4) C 5) E 6) F |
Sort option
SORT or ASC sorts in ascending order. DESC sorts in descending order.
Example
| Command> | sunion myset1 myset2 sort |
| Result> |
1) A 2) B 3) C 4) D |
| Command> | sunion myset1 myset2 desc |
| Result> |
1) D 2) C 3) B 4) A |
| The sort option is available on Enterprise servers. |
Syntax
SUNION key [key ...] [sort|asc|desc]
- Available since version 1.0.0.
- Time complexity is O(N), where N is the total number of members in the given sets.
| SQL Select | On Redis Enterprise 7.3.0 or later, try SELECT. |
| Related commands | SINTER, SDIFF, SUNIONSTORE |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << SCARD | SUNION | SINTER >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
