Persistence: RDB and AOF
Harry
· 13 Sep 2026
· 1 views
Why Persist at All
Redis keeps data in memory, so a restart would lose everything unless persistence is configured. Two mechanisms exist: RDB snapshots and AOF (Append Only File).
RDB Snapshots
save 900 1 # if >=1 change, save after 900s
save 300 10
dir /var/lib/redis
dbfilename dump.rdbRDB is a compact point-in-time snapshot, perfect for backups and fast startup, but it can lose the last few minutes of writes.
AOF
appendonly yes
appendfsync everysec # balance of flush cost and safetyAOF logs each write command and replays it on restart, losing at most the fsync window (seconds). It grows, but Redis rewrites it automatically.
Choosing a Strategy
- RDB only - fast restarts, some data loss.
- AOF only - durable, slightly slower restarts.
- Both (default since Redis 7) - snapshot plus log.
Backup Practice
Use redis-cli SAVE or BGSAVE to produce snapshots, copy them off-machine regularly, and test restoration in a staging instance.
Key Points
- RDB snapshots and AOF logs cover recovery.
- appendfsync everysec is the pragmatic default.
- Prefer both modes for production data.
- Backups must live off the Redis host too.