YouTip LogoYouTip

Sets Sdiff

Redis Sdiff Command

Redis Sdiff Command

--

Redis Tutorial

Redis Tutorial Redis Introduction Redis Installation Redis Configuration Redis Data Types

Redis Commands

Redis Commands Redis Keys Redis Strings Redis Hashes Redis Lists Redis Sets Redis Sorted Sets Redis HyperLogLog Redis Pub/Sub Redis Transactions Redis Scripting Redis Connection Redis Server Redis GEO Redis Stream

Advanced Redis Tutorial

Redis Backup and Recovery Redis Security Redis Performance Testing Redis Client Connection Redis Pipelining Redis Partitioning Java Using Redis PHP Using Redis Redis Lists Redis Sorted Sets

Redis Sdiff Command

Image 3 Redis Sets

The Redis Sdiff command returns the difference between the first set and other sets, which can also be considered the unique elements in the first set. Non-existent set keys are treated as empty sets.

The difference result comes from the preceding FIRST_KEY, rather than the following OTHER_KEY1, nor is it the difference of the entire FIRST_KEY OTHER_KEY1..OTHER_KEYN.

Example:

key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SDIFF key1 key2 key3 = {b,d}

Syntax

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

redis 127.0.0.1:6379> SDIFF FIRST_KEY OTHER_KEY1..OTHER_KEYN

Available Version

>= 1.0.0

Return Value

A list containing the members of the difference.

Example

redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SDIFF key1 key2
1) "a"
2) "b"
redis>
Image 4 Redis Sets

← Sets SdiffstoreSets Scard β†’