SDIFF command in redis

SDIFF key1 key2 ... keyN

Return the members of a set resulting from the difference between the first set provided and all the successive sets. 

TIME COMPLEXITY: O(N) with N being the total number of elements of all the sets

Example:

key1 = x,a,b,c

key2 = c

key3 = a,d

SDIFF key1,key2,key3 => x,b

Note:

Non-existing keys are considered empty sets.

RETURN VALUE: Multi bulk reply, specifically the list of common elements.

Syntax:

SDIFF key1 key2 ... keyN

Example

redis:6379> SADD key1 x a b c
(integer) 4
redis:6379> SADD key2 c
(integer) 1
redis:6379> SADD key3 a d
(integer) 2
redis:6379> SDIFF key1 key2 key3
1) "x"
2) "b"

Output

x

b

No comments:

Post a Comment