🔴 Redis
Beginner
What are SADD and SMEMBERS in Redis?
Answer
SADD key member [member ...] adds one or more members to a Redis Set, silently ignoring duplicates (Sets only store unique values). SMEMBERS key returns all members of the Set in an arbitrary order. Redis Sets support powerful set-theory operations: SUNION (union of multiple sets), SINTER (intersection), SDIFF (difference). These make Sets ideal for social features: "mutual friends" is SINTER of two friend sets; "you may know" is SDIFF; "combined tags" is SUNION. SISMEMBER key member checks membership in O(1) time. For very large sets where memory is a concern and approximate answers are acceptable, consider HyperLogLog instead of Sets for counting unique elements.