w3resource

Redis Sets: SDIFF

SDIFF key1 [key2]

Redis SDIFF command is used to return the members of the set resulting from the difference between the first set and all the successive sets. If keys do not exist in redis then it is considered as empty sets.

Syntax:

SDIFF FIRST_KEY OTHER_KEY1..OTHER_KEYN

Available since :

1.0.0.

Return Value:

Array reply, list with members of the resulting set.

Return Value Type:

Array

How sdiff mycolor1 mycolor2 mycolor3 works :

mycolor1 = {R G B}

mycolor2 = {G Y}

SDIFF mycolor1 mycolor2 = {R B}

In the first set to remove the member in the second set.

Therefore, they remain only in the first set member.

mycolor3 = {B P}

SDIFF mycolor1 mycolor2 mycolor3 = {R}

In the first set of the second, it eliminates member in the third set.

The number of keys is not limited.

Example: Redis SDIFF

127.0.0.1:6379> SADD mycolor1 R G B
(integer) 3
127.0.0.1:6379> SADD mycolor2  G Y
(integer) 2
127.0.0.1:6379> sdiff mycolor1 mycolor2
1) "R"
2) "B"
127.0.0.1:6379> SADD mycolor3  B P
(integer) 2
127.0.0.1:6379> sdiff mycolor1 mycolor2 mycolor3
1) "R"


Follow us on Facebook and Twitter for latest update.