SDIFFSTORE

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Get the set difference and store it in a new set

Usage: sdiffstore destination_key source_key1 source_key2.
The behavior is the same as SDIFF. The extra part is storing the result set in the specified destination_key.
myset1 = { A, B, C }
myset2 = { B, D }
SDIFFSTORE dest_key myset1 myset2 = { A, C }

Example

Command>sadd myset1 A B C
Result>3
Command>sadd myset2 B D
Result>2
Command>sdiffstore dest_key myset1 myset2
Result>2
Command>smembers dest_key
Result> 1) A
2) C

View animation



Get the difference of three sets and store it

Usage: sdiffstore destination_key source_key1 source_key2 source_key3.
myset1 = { A, B, C }
myset2 = { B, D }
myset3 = { C, E }
SDIFFSTORE dest_key myset1 myset2 myset3 = { A }

There is no limit on the number of keys.

Example

Command>sadd myset3 C E
Result>2
Command>sdiff dest_key myset1 myset2 myset3
Result>1
Command>smembers dest_key
Result> 1) A


A source key can be specified as the destination key

SDIFFSTORE myset1 myset1 myset2 myset3
The previous contents of myset1 are cleared, and the result is stored in myset1.

Example

Command>sdiffstore myset1 myset1 myset2 myset3
Result>1
Command>smembers myset1
Result> 1) A


Syntax

SDIFFSTORE destination_key source_key [source_key ...]

  • Available since version 1.0.0.
  • Time complexity is O(N). N is the total number of members in the given sets.
Related commands SUNION, SINTER, SDIFFSTORE
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< SINTERSTORE SDIFFSTORE SISMEMBER >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.