Lesson 8 / 18
Sets
Unordered, unique members — built for membership checks and set math.
SADD & SMEMBERS
A set stores each value once. SISMEMBER checks membership in constant time — no scanning needed.
SADD tags:post:9 "redis" "cache" "redis"
SMEMBERS tags:post:9
SISMEMBER tags:post:9 "cache"
Output:
(integer) 2 1) "redis" 2) "cache" (integer) 1
Set operations
Redis computes intersections and unions server-side — useful for "mutual friends" or "common tags" style features.
SADD tags:post:9 "redis" "cache"
SADD tags:post:12 "redis" "db"
SINTER tags:post:9 tags:post:12
Output:
1) "redis"