SDIFF key [key …]

Available since 1.0.0.

Time complexity: O(N) where N is the total number of elements in all given sets.

Returns the members of the set resulting from the difference between the first set and all the successive sets.

For example:

  1. key1 = {a,b,c,d}
  2. key2 = {c}
  3. key3 = {a,c,e}
  4. SDIFF key1 key2 key3 = {b,d}

Keys that do not exist are considered to be empty sets.

*Return value

Array reply: list with members of the resulting set.

*Examples

redis> SADD key1 "a"

  1. (integer) 1

redis> SADD key1 "b"

  1. (integer) 1

redis> SADD key1 "c"

  1. (integer) 1

redis> SADD key2 "c"

  1. (integer) 1

redis> SADD key2 "d"

  1. (integer) 1

redis> SADD key2 "e"

  1. (integer) 1

redis> SDIFF key1 key2

  1. 1) "a"
  2. 2) "b"
redis>