Set Commands
Set commands allow you to store unique string elements. Sets are unordered and do not allow duplicate elements. Multiple set operations such as intersection and union are supported.
Command List
SADD
Adds one or more members to a set
SCARD
Returns the number of elements in a set
SINTER
Returns the intersection of all given sets
SISMEMBER
Determines whether a member is a member of a set
SMEMBERS
Returns all members in a set
SPOP
Removes and returns a random element from a set
SRANDMEMBER
Returns one or more random members from a set without removing them
SREM
Removes one or more members from a set
SUNION
Returns the union of all given sets
SUNIONSTORE
Stores the union of all given sets in a specified set
SDIFFSTORE
Computes the difference of all given sets and stores it in a specified set
SINTERSTORE
Computes the intersection of all given sets and stores it in a specified set
SMOVE
Moves a member from one set to another
Use Cases
Set commands are ideal for tag systems, friend relationships, deduplication statistics, and other scenarios. Due to the uniqueness characteristic of sets, deduplication functions can be easily implemented, while set operations can conveniently handle relational queries.
For detailed usage and parameters of each command, please refer to the individual command documentation linked above.