Redis Sdiff Command
The Redis Sdiff command returns the difference between the first set and other sets, which can also be considered the elements unique to the first set. A non-existent set key is treated as an empty set.
The result of the difference comes from the preceding FIRST_KEY, not the following OTHER_KEY1, nor the difference of the entire FIRST_KEY OTHER_KEY1..OTHER_KEYN.
Example:
key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SDIFF key1 key2 key3 = {b,d}
Syntax
The basic syntax of the redis Sdiff command is as follows:
redis 127.0.0.1:6379> SDIFF FIRST_KEY OTHER_KEY1..OTHER_KEYN
Available Version
= 1.0.0
Return Value
A list of the difference members.
Example
redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SDIFF key1 key2
1) "a"
2) "b"
redis>
Redis Set