Level 1 · Redis Foundations¶
Level 1 takes you from "Redis is a cache" to writing correct application code against it. That's more than
learning GET and SET. You need to know why one KEYS * made an unrelated PING wait 149 ms, why a plain
SET quietly removed a session's expiry, why read-then-write counters lost 89% of their increments, and why
a client library's helpful automatic retry applied one INCR twice.
Every lesson is built from commands run against a real server, Redis 8.10.2, and every output shown is what that server (or the client library) actually returned, errors included.
Prerequisites: basic programming in Python or JavaScript, and comfort at a terminal. No Redis experience is needed. If you know a relational database, you'll see where Redis's model differs.
Modules¶
- What Redis Is: One Thread, Memory & a Local Lab — install Redis, start a throwaway server, measure memory per key, and watch one slow command block every client.
- redis-cli & the RESP Protocol — speak RESP2 and RESP3 by hand, raw vs
formatted output,
--pipeloading 100,000 keys in 79 ms,MONITORand--bigkeys. - Strings, Counters & Expiry —
SET's options including 8.4'sIFEQ, atomic counters vs lost updates, float pitfalls, TTLs and the overwrite trap. - The Keyspace: Naming, SCAN & Safe Deletes — key naming, cursor iteration
and its guarantees,
UNLINKvsDELon a 2-million-field hash, pattern deletes that don't block. - Hashes & Per-Field Expiry — objects as hashes,
HEXPIRE/HSETEX/HGETDEL, and why a small hash beat both JSON and separate keys on memory. - Lists: Queues, Stacks & Blocking Pops — capped lists, which list commands are really
O(N),
BLPOPworkers andLMOVEfor safer handoff. - Sets: Membership, Set Algebra & Random Picks — dedupe with
SADD, intersections andSINTERCARD, random draws, and the cost of algebra on million-member sets. - Sorted Sets: Rankings, Ranges & Time Windows — leaderboards,
ZADDflags, score and lex ranges, delayed jobs, sliding windows and O(log N) measured. - Clients: redis-py & node-redis — shared clients and pools, RESP3 defaults, pipelines vs transactions, and timeouts with retries that can double-apply writes.
- Project — URL Shortener with Click Analytics — a tested shortener using every type in this level, including the overwrite bug its tests caught.
After Level 1¶
You can store and change data correctly with Redis's five core types. Level 2 goes underneath and beyond them:
how each type is encoded in memory and how to shrink it, bitmaps and HyperLogLog for counting at scale,
geospatial indexes, streams with consumer groups, Pub/Sub, and the two ways to make several commands atomic,
MULTI/WATCH and server-side Lua functions.