Apply sorted sets for leaderboards, geospatial commands, HyperLogLog for cardinality estimation, Redis Streams, and ZADD flag semantics.
0 / 5 completed
1 / 5
What are Redis sorted sets and what commands are used to add and retrieve members?
Sorted sets:ZADD key score member adds or updates. ZRANGE key 0 -1 WITHSCORES returns all members in ascending score order. ZREVRANGE returns in descending order. ZRANGEBYSCORE key 1000 2000 returns members with scores in a range. Sorted sets use a skip list internally — O(log n) for add/remove/range queries.
2 / 5
What Redis geospatial commands enable and how are locations stored internally?
Redis geospatial: coordinates are encoded as a 52-bit geohash stored as the score in a sorted set. GEOADD locations 51.5 -0.1 "london" stores London. GEOSEARCH locations FROMLONLAT 51.5 -0.12 BYRADIUS 5 km ASC COUNT 10 returns the 10 nearest locations. The sorted set encoding enables range queries by proximity without a dedicated spatial index.
3 / 5
What is HyperLogLog in Redis and what trade-off does it make?
HyperLogLog: counting unique visitors per page with a set would require storing every visitor ID. A HyperLogLog gives an approximate count (±0.81%) using only 12KB of memory regardless of whether you have 1,000 or 1 billion unique elements. PFMERGE daily weekly1 weekly2 merges multiple HyperLogLogs, enabling hierarchical rollups.
4 / 5
What are Redis Streams and how do they differ from Pub/Sub?
Redis Streams: Pub/Sub is fire-and-forget — offline consumers miss messages. Streams persist messages with auto-generated IDs (1704067200000-0 timestamp-sequence). Consumer groups allow parallel processing with acknowledgement: XREADGROUP GROUP workers consumer1 COUNT 10 STREAMS mystream > claims messages; XACK confirms processing.
5 / 5
What does ZADD NX versus ZADD XX control in Redis sorted sets?
ZADD flags:ZADD leaderboard NX 1500 "alice" only adds alice if she doesn't already have a score — ignores updates. ZADD leaderboard GT 2000 "alice" only updates if the new score (2000) is greater than the current score — ensuring scores can only increase, useful for high-score leaderboards where you never want to overwrite a better score with a worse one.