Level 2 · Data Structures in Depth¶
Level 1 used Redis's core types correctly. Level 2 goes underneath them and beyond them. You'll see why one extra
sorted-set member made a key 12× larger, why a million small values fit in 7.9 MB instead of 46 MB, and how 10
million unique visitors fit in 12 KB. You'll also see why a stream reader that passes $ loses half its messages,
why a slow subscriber gets cut off at 32 MB, and why a Lua script ran the same transfers 7× faster than WATCH.
Some results surprised us, and they're reported as found. On the Homebrew build of Redis 8.10.2 used here,
BITCOUNT returned wrong totals above 2^21. Lesson 02 shows the evidence, the comparison with Valkey, and a
workaround. Several commands used here are very recent (8.2's XACKDEL, 8.6's idempotent XADD, 8.8's XNACK),
and each lesson says which version introduced them.
Prerequisites: Level 1, or equivalent experience with Redis's strings, hashes, lists, sets and sorted sets and a client library.
Modules¶
- Encodings & Memory — listpack, intset, skiplist and quicklist, the thresholds
between them, hash bucketing, and reading fragmentation in
INFO memory. - Bitmaps & Bitfields — daily-active-user bitmaps,
BITOPset algebra, packed counters with overflow control, the sparse-offset trap, and aBITCOUNTbug found. - HyperLogLog, Bloom Filters & Other Sketches — approximate counting and membership with measured error rates: HyperLogLog, Bloom, Cuckoo, Count-Min and Top-K.
- Geospatial Indexes —
GEOADDandGEOSEARCH, nearest-N on a million points, whyANYmatters, and the spherical model's 0.2% error. - Streams: An Append-Only Log — entry IDs, ranges,
XREADwithout losing messages, bounded trimming, and idempotentXADD. - Stream Consumer Groups & Recovery — the pending entries list,
XACK, recovering a crashed worker withXAUTOCLAIM, dead letters,XACKDELandXNACK. - Pub/Sub, Sharded Pub/Sub & Keyspace Notifications — broadcast messaging, slow-subscriber disconnects, sharded channels, and how late expiry events really are.
- Transactions: MULTI, EXEC & WATCH — what a Redis transaction guarantees (no rollback), and optimistic locking that took overdrafts from 2,815 to zero.
- Lua Scripts & Redis Functions — atomic server-side logic, conversion traps,
BUSYscripts that can't be killed, and persistent function libraries. - Project — Game Leaderboard & Activity Feed — a Functions-based weekly leaderboard with first-come tie-breaking, a trimmed activity stream and an idempotent badge worker.
After Level 2¶
You know what each structure costs and how to compose them atomically. Level 3 applies that to the jobs Redis is most often hired for: caching (and the stampedes, invalidation bugs and eviction surprises that come with it), rate limiting, distributed locks and their limits, sessions, reliable job queues, JSON documents, and the query engine's secondary and vector indexes.