Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Sdiffstore Command

Redis Sdiffstore Command

Redis Set

The Redis Sdiffstore command stores the difference between the given sets in the specified set. If the specified set key already exists, it is overwritten.

Syntax

The basic syntax of the redis Sdiffstore command is as follows:



redis 127.0.0.1:6379> SDIFFSTORE DESTINATION_KEY KEY1..KEYN 

Available Version

= 1.0.0

Return Value

The number of elements in the result set.

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> SDIFFSTORE destset myset myset2

(integer) 2

redis 127.0.0.1:6379> SMEMBERS destset

1) "foo"

2) "bar"

Redis Set