SDIFF

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

Get the set difference

Usage: sdiff key1 key2.
myset1 = { A, B, C }
myset2 = { B, D }
SDIFF myset1 myset2 = { A, C }

This removes members that are in the second set from the first set.
So only members that exist in the first set remain.

Example

Command>sadd myset1 A B C
Result>3
Command>sadd myset2 B D
Result>2
Command>sdiff myset1 myset2
Result> 1) A
2) C

View animation


Difference of three sets

Usage: sdiff key1 key2 key3.
myset1 = { A, B, C }
myset2 = { B, D }
myset3 = { C, E }
SDIFF myset1 myset2 myset3 = { A }

This removes members that are in the second and third sets from the first set.
There is no limit on the number of keys.

Example

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

Sort feature

SORT or ASC sorts in ascending order, and DESC sorts in descending order.

Example

Command>sdiff myset1 myset2 sort
Result> 1) A
2) C
Command>sdiff myset1 myset2 desc
Result> 1) C
2) A
Note The sort feature is available on the Enterprise server.


Syntax

SDIFF key [key ...] [sort|asc|desc]

  • Available since version 1.0.0.
  • Time complexity is O(N). N is the total number of members in the given sets.
SQL Select If you have Redis Enterprise 7.3.0 or later, try SELECT.
Related commands SUNION, SINTER, SDIFFSTORE
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< SINTER SDIFF SUNIONSTORE >>

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