Redis: RDB vs. AOF Persistence
Salvatore Sanfilippo (antirez) has given us the fastest key-value store on the planet. But Redis is "ephemeral" by default. If you want your data to survive a restart, you have two main options.
RDB (Redis Database Backup)
RDB is a compact point-in-time snapshot of your dataset. It's great for backups and fast restarts.
# redis.conf snapshotting rules
save 900 1 # Save after 900s if 1 key changed
save 300 10 # Save after 300s if 10 keys changed
The magic of RDB is fork(). Redis forks a child process, which writes the entire memory state to disk while the parent continues to serve requests. Since it uses "copy-on-write," the memory overhead is manageable unless you have a massive write volume.
AOF (Append Only File)
AOF logs every write operation received by the server. It's much more durable than RDB.
appendonly yes
appendfsync everysec
With everysec, you lose at most one second of data. However, the AOF file grows indefinitely. This is where AOF Rewrite comes in. Redis can recreate the AOF in the background by reading the current state of memory and writing the shortest sequence of commands needed to rebuild it.
Which one?
If you care about performance and can lose a few minutes of data, use RDB. If you need maximum durability, use both. Just remember that if both are enabled, Redis will use the AOF on startup because it's guaranteed to be more complete.