Concept Flow - SUNION, SINTER, SDIFF set operations
Start with Sets A and B
Perform Set Operation
Return Resulting Set
End
Start with two sets, pick one of the operations (union, intersection, difference), perform it, and get the resulting set.
SADD setA 1 2 3 SADD setB 2 3 4 SUNION setA setB SINTER setA setB SDIFF setA setB
| Step | Command | SetA | SetB | Operation | Result |
|---|---|---|---|---|---|
| 1 | SADD setA 1 2 3 | 1,2,3 | - | - | - |
| 2 | SADD setB 2 3 4 | 1,2,3 | 2,3,4 | - | - |
| 3 | SUNION setA setB | 1,2,3 | 2,3,4 | Union | 1,2,3,4 |
| 4 | SINTER setA setB | 1,2,3 | 2,3,4 | Intersection | 2,3 |
| 5 | SDIFF setA setB | 1,2,3 | 2,3,4 | Difference | 1 |
| 6 | SDIFF setB setA | 1,2,3 | 2,3,4 | Difference | 4 |
| 7 | End | 1,2,3 | 2,3,4 | - | - |
| Variable | Start | After 1 | After 2 | After 3 | After 4 | After 5 | Final |
|---|---|---|---|---|---|---|---|
| setA | empty | 1,2,3 | 1,2,3 | 1,2,3 | 1,2,3 | 1,2,3 | 1,2,3 |
| setB | empty | empty | 2,3,4 | 2,3,4 | 2,3,4 | 2,3,4 | 2,3,4 |
| Result | none | none | none | 1,2,3,4 | 2,3 | 1 | 1 (last result) |
SUNION key1 key2 ... - returns all unique elements from all sets combined SINTER key1 key2 ... - returns elements common to all sets SDIFF key1 key2 ... - returns elements in first set not in others All commands operate on Redis sets and return a set result Sets remain unchanged after these operations