Redis Persistence in Depth
Tested 2026-11-26 on macOS 14.1, Apple M3 Pro; Docker Desktop 4.27.2 (Engine 25.0.3), 11 CPUs and 8 GB for the Docker VM · with Redis 8.10.3 (official Docker image), Docker Desktop 4.27.2 (Engine 25.0.3, macOS), Go 1.26.11, go-redis v9.23.0 · by the fromzero project · CC BY 4.0
Your app sends every new order, session or job to Redis, and Redis keeps all of it in memory.
Then the container is killed: an out-of-memory kill, a crashed host, a docker kill. On Redis’s default settings
it comes back empty: 50 orders written, 0 left.
Turn on snapshots every 10 seconds and kill it again: this time 467 writes that Redis had acknowledged to your app are gone.
A log of every write loses less, and costs more disk work. Which to use, and how much you can lose, is a decision you can measure instead of guess.
This course has you crash Redis on purpose, count what was lost, and read why from Redis’s own counters and files.
You should already have used Redis a little: SET, GET, redis-cli, and run a container with Docker.
Lesson 1 recaps only what persistence depends on (the process, the kernel’s cache, the disk).
By the end you’ll be able to:
- say what a crash, a clean stop and a power cut each take from Redis, and why;
- read
INFO persistenceand the logs to tell what the next crash would lose, and why a save failed; - configure RDB snapshots, the append-only file, or both, with an fsync policy you chose on purpose;
- prove your choice: crash Redis under load, count the lost writes and time the restart.
How it works
Each lesson opens with the problem, then an animated, step-by-step picture (press Play, or step with the
arrow keys), then the mechanism in plain words, with optional Go deeper sections at production depth. Each
practical has you write the config and a small Go program yourself in ~/redis-persistence/: requirements, a
hint, a hidden solution, a “predict first” question and a part where you break it on purpose. One script,
./lab, does the plumbing:
./lab setup p0starts Redis 8.10.3 in a Docker container with its data in a volume, and gives you a startingredis.confwith persistence off. It prints one line per step (every command goes tolab.log) and keeps what you already have../lab check pNtells you whether your work is right. It only reads../lab reset pNstarts you at a practical with a fresh container. It asks first and never touches your files../lab updatefetches the newest script, with the next practical’s checks.
You need Docker and Go 1.21 or newer (Go fetches the newer toolchain the Redis client needs by itself) on macOS or Linux.
Path
| Lesson | Practical | You’ll be able to |
|---|---|---|
| 1 · Why a restart empties Redis | say where a write lives between OK and the disk | |
| 2 · RDB snapshots | 0 · Your Redis, crashed | turn on snapshots, predict a crash’s loss from INFO, fix a MISCONF |
| 3 · The append-only file and fsync | choose an fsync policy, knowing what a process crash and a power cut each lose | |
| 4 · Persistence in production | 1 · Prove your setting | measure lost writes and restart time for your config, and recover a damaged AOF |
What your folder will look like
~/redis-persistence/
├── lab the lab script: ./lab setup|check|reset pN
├── lab.log every command ./lab ran, with its output
├── conf/
│ └── redis.conf the config your container starts with (mounted into it)
├── writer/ your Go program: numbered writes, prints the last one Redis acknowledged
│ ├── go.mod
│ └── main.go
├── crashtest/ your crash harness: writes, kills, restarts, reports lost writes and restart time
│ ├── go.mod
│ └── main.go
├── results.md your numbers for each setting, and your choice
└── aof-backup.tgz the copy of the AOF you make before fixing it