Redis persistence: RDB snapshots vs AOF logging explained
RDB snapshot, AOF append-only file, BGSAVE, AOF rewrite, durability tradeoffs, redis.conf persistence settings, no persistence mode
Persistence in Redis
Redis is in-memory but can persist data to disk so it survives restarts. Two mechanisms exist; you can use one or both.
RDB — point-in-time snapshots
Redis forks a child process and writes a compact binary snapshot to dump.rdb. Triggered automatically by rules in redis.conf or manually with BGSAVE.
# redis.conf — save if 100 writes in 60 seconds
save 60 100
# Manual snapshot
redis-cli BGSAVERDB is fast to restore but you lose writes since the last snapshot.
AOF — append-only file
Every write command is appended to appendonly.aof. On restart, Redis replays the file to reconstruct state. More durable, larger file, slightly slower writes.
# redis.conf
appendonly yes
appendfsync everysec # fsync once per second (recommended)Choosing a strategy
Use RDB alone for caches where some data loss is acceptable. Use AOF (or both) when you cannot afford to lose writes. Set appendfsync always for maximum durability at the cost of throughput. Set appendfsync no to let the OS decide — fastest but least safe. For ephemeral caches, disable both and add save "" to the config.
