Reading — step 1 of 3
Redis Sets
~1 min readSets & Sorted Sets
SADD, SMEMBERS & SISMEMBER
Redis sets are unordered collections of unique strings.
Commands
| Command | Description | Returns |
|---|---|---|
SADD key member [member ...] | Add members | Count of NEW members added |
SMEMBERS key | Get all members | RESP array |
SISMEMBER key member | Check membership | :1 or :0 |
SCARD key | Get size | Integer |
SREM key member [member ...] | Remove members | Count removed |
Uniqueness
Adding a duplicate does nothing: SADD myset a a a returns :1 (only one new member).
Implementation
Use your language's hash set:
- Python:
set() - JavaScript:
Set - Go:
map[string]bool - C++:
std::unordered_set<std::string>
Note: For testing SMEMBERS, we sort the output alphabetically to ensure deterministic comparison.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…