Redis Tutorial with Examples.
Redis tutorial: in-memory data structures, from strings, hashes and sorted sets to pub/sub, streams, Lua scripting and caching.
Beginner
Start here — no prior experience needed
Redis in Five Commands: SET, GET, TYPE, and a WRONGTYPE Error
Run a real Redis server in Docker in one command, then hit the error every new user eventually hits: calling GET on a key that isn't a string.
Expiry, Atomic Counters, and the -1 vs -2 TTL Trap
TTL returns -1 for a key that never expires and -2 for one that's already gone — mixing those up is the most common expiry bug. Then: INCR's atomic counters, and the error when a string isn't a number.
Hashes, Lists, and Sets: Structures That Deduplicate and Enforce Order For You
SADD silently drops duplicates and returns how many were actually new, RPUSH+LPOP gives you a FIFO queue for free, and HINCRBY enforces numeric fields the same way INCR does for strings.
Sorted Sets: Building a Leaderboard, and the Ascending-Order Trap
ZRANGE returns lowest score first by default — a real surprise the first time you build a leaderboard and see the worst player listed first. ZREVRANGE, ZRANK, and range queries fix it.
Intermediate
For developers with core concepts down
MULTI/EXEC Transactions and the WATCH-Based Optimistic Lock
Queue commands with MULTI, run them atomically with EXEC — then watch a real transaction abort mid-flight when another client changes a WATCHed key first.
Pub/Sub: Channels, Patterns, and the Message That Never Arrives
Publishing to a channel with no subscribers doesn't queue the message for later — it's just gone. Real fan-out to multiple subscribers, pattern subscriptions, and sharded Pub/Sub follow.
RDB vs AOF: What Survives a Hard Kill and What Doesn't
A graceful restart saves your data by default — Redis snapshots on SIGTERM. A hard kill (docker kill, a power loss, an OOM kill) gives it no such chance, and only AOF protects against that. Then: the new BACKUP command family.
Replication: A Read-Only Replica, and What WAIT Actually Guarantees
Writing directly to a replica fails with READONLY by design — and WAIT doesn't error when it can't reach the number of replicas you asked for, it just tells you how many actually acknowledged in time.
ACL: a User Restricted to One Key Pattern and One Command
A default Redis install lets every connection run every command against every key. ACL SETUSER changes that — including a real NOPERM the moment a restricted user reaches outside its allowed keys or commands.
maxmemory and Eviction: What Redis Throws Away When It's Full
Cap Redis at 3 MB and fill it: watch noeviction refuse writes, volatile-lru fail with no TTLs, and LRU, LFU and LRM pick different keys to throw away.
Cache-Aside with Redis: Stale Reads, Races and Stampedes
Put Redis in front of a slow database and break it on purpose: a stale read, two invalidation races, a 50-request stampede, and the fix for each, measured.
Advanced
Production-grade patterns for experienced engineers
Lua Scripting, EVALSHA's NOSCRIPT, and Functions That Forget to Declare no-writes
A guessed script hash fails with a real NOSCRIPT error, and a Function callable via FCALL refuses to run through FCALL_RO until it explicitly declares itself read-only — Redis won't infer that for you.
Clustering: Hash Slots, MOVED, and the CROSSSLOT Error
A real 3-node cluster, a real MOVED redirect from writing to the wrong node, and a real CROSSSLOT error the first time a multi-key command touches two different slots — fixed with a hash tag.
Redis Streams and Consumer Groups: Crashes, Re-delivery and Dead Letters
Redis Streams keep what Pub/Sub drops. Split work across consumers, crash one before XACK, reclaim its entry with XAUTOCLAIM, dead-letter a poison message.
Also part of Redis
Taught in other topics. Each link opens the lesson in its home topic.
Cache Eviction: When LRU and LFU Actually Disagree
LRU evicts whatever wasn't touched most recently; LFU evicts whatever was touched least often. The same access sequence can make them evict different keys.
ACID vs BASE: the Lost Update Neither Engine Prevents by Default
A naive read-then-write race loses an update in both PostgreSQL and Redis when neither uses locking — the real difference is that Postgres ships a built-in fix (SELECT ... FOR UPDATE) and a raw key-value GET/SET pair has no equivalent.
Distributed Locks: A Real Double-Booking Bug, Fixed With a Redis Lock
Two processes racing on the same booking slot really do double-book it. A Redis SET NX PX lock fixes it — a blind DEL unlock reintroduces the bug.