Redis Sets: SDIFF
Redis SDIFF Command
Redis SDIFF command is used to return the members of the set resulting from the difference between the first set and all the successive sets. If keys do not exist in redis then it is considered as empty sets.
Here are some common uses and scenarios for the "SDIFF" command:
- Set Difference: Calculate the difference between multiple sets, identifying elements unique to the first set.
- Exclusion Operations: Determine which members are exclusive to one set compared to others.
- Data Comparison: Compare datasets to find unique items in the first set.
- Filtering:. Filter out common elements, leaving only the unique elements in the first set.
- Analysis and Reporting: Perform analysis by subtracting sets to understand differences between collections.
Syntax:
SDIFF FIRST_KEY OTHER_KEY1..OTHER_KEYN
Available since :
1.0.0.
Return Value:
Array reply, list with members of the resulting set.
Return Value Type:
Array
How sdiff mycolor1 mycolor2 mycolor3 works :
mycolor1 = {R G B}
mycolor2 = {G Y}
SDIFF mycolor1 mycolor2 = {R B}
In the first set to remove the member in the second set.
Therefore, they remain only in the first set member.
mycolor3 = {B P}
SDIFF mycolor1 mycolor2 mycolor3 = {R}
In the first set of the second, it eliminates member in the third set.
The number of keys is not limited.
Example: Redis SDIFF
127.0.0.1:6379> SADD mycolor1 R G B (integer) 3 127.0.0.1:6379> SADD mycolor2 G Y (integer) 2 127.0.0.1:6379> sdiff mycolor1 mycolor2 1) "R" 2) "B" 127.0.0.1:6379> SADD mycolor3 B P (integer) 2 127.0.0.1:6379> sdiff mycolor1 mycolor2 mycolor3 1) "R"
Previous:
Redis Sets SADD
Next:
Redis Sets SDIFFSTORE
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics