sdiff
SDIFF
Get the set difference
Usage: sdiff key1 key2.
myset1 = { A, B, C }
myset2 = { B, D }
SDIFF myset1 myset2 = { A, C }
This removes members that are in the second set from the first set.
So only members that exist in the first set remain.
Example
| Command> | sadd myset1 A B C |
| Result> | 3 |
| Command> | sadd myset2 B D |
| Result> | 2 |
| Command> | sdiff myset1 myset2
|
| Result> |
1) A
2) C
|
View animation
Difference of three sets
Usage: sdiff key1 key2 key3.
myset1 = { A, B, C }
myset2 = { B, D }
myset3 = { C, E }
SDIFF myset1 myset2 myset3 = { A }
This removes members that are in the second and third sets from the first set.
There is no limit on the number of keys.
Example
| Command> | sadd myset3 C E |
| Result> | 2 |
| Command> | sdiff myset1 myset2 myset3
|
| Result> |
1) A
|
Sort feature
SORT or ASC sorts in ascending order,
and DESC sorts in descending order.
Example
| Command> | sdiff myset1 myset2 sort
|
| Result> |
1) A
2) C
|
| Command> | sdiff myset1 myset2 desc
|
| Result> |
1) C
2) A |
Syntax
SDIFF key [key ...] [sort|asc|desc]
- Available since version 1.0.0.
- Time complexity is O(N). N is the total number of members in the given sets.