Redis – Set Sdiff Command

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

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

Return Value

Array reply, list with members of the resulting set.

Syntax

Following is the basic syntax of Redis SDIFF command.

redis 127.0.0.1:6379> SDIFF FIRST_KEY OTHER_KEY1..OTHER_KEYN

Example

redis 127.0.0.1:6379> SADD myset "hello" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset "foo" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset "bar" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset2 "hello" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset2 "world" 
(integer) 1 
redis 127.0.0.1:6379> SDIFF myset myset2 
1) "foo" 
2) "bar" 

Leave a Reply