Reading — step 1 of 3
Append-Only File
~1 min readAdvanced Features
AOF — Append-Only File Logging
AOF is Redis's second persistence mechanism. Instead of snapshotting all data, it logs every write command.
How It Works
- Every write command (SET, DEL, LPUSH, etc.) is appended to a log
- On restart, Redis replays the entire log to rebuild state
- The log only grows — periodic "rewrite" compacts it
RDB vs AOF
| Feature | RDB | AOF |
|---|---|---|
| Data loss window | Minutes (between saves) | Seconds (fsync policy) |
| File size | Compact | Larger (every command) |
| Restore speed | Very fast | Slower (replays commands) |
| CPU cost | High (serialization) | Low (just append) |
Real Redis Recommendation
Use both: RDB for fast restarts + AOF for minimal data loss. Redis can even rewrite the AOF in the background.
What You'll Build
AOF ON/OFF— toggle loggingAOF DUMP— view the command logAOF REPLAY— rebuild state from the log- Only write commands are logged (not GET, LRANGE, etc.)
This teaches the fundamental concept behind write-ahead logging — used in every serious database.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…