0
0
Redisquery~5 mins

Redis persistence overview (RDB, AOF)

Choose your learning style9 modes available
Introduction

Redis persistence saves your data so it is not lost when the server restarts or crashes.

You want to keep your data safe even if Redis stops unexpectedly.
You need to reload data quickly after a restart.
You want to balance between fast saving and minimal data loss.
You want to keep a history of changes for recovery.
You want to choose how often Redis saves data based on your needs.
Syntax
Redis
RDB (snapshotting): Redis saves data to a dump file at intervals.
AOF (Append Only File): Redis logs every write command to a file.

RDB creates snapshots of your data at set times.

AOF records every change, so it can replay commands to restore data.

Examples
This RDB config saves a snapshot if 1 key changes in 900 seconds, or 10 keys in 300 seconds, or 10000 keys in 60 seconds.
Redis
save 900 1
save 300 10
save 60 10000
This AOF config turns on logging and syncs the file every second for durability.
Redis
appendonly yes
appendfsync everysec
Sample Program

This shows checking current RDB save settings, checking if AOF is on, then turning AOF on.

Redis
127.0.0.1:6379> CONFIG GET save
1) "save"
2) "900 1 300 10 60 10000"
127.0.0.1:6379> CONFIG GET appendonly
1) "appendonly"
2) "no"
127.0.0.1:6379> CONFIG SET appendonly yes
OK
127.0.0.1:6379> CONFIG GET appendonly
1) "appendonly"
2) "yes"
OutputSuccess
Important Notes

RDB is faster for backups but may lose recent changes if Redis crashes.

AOF is safer but can be slower and the file grows over time.

You can use both together for better safety and faster recovery.

Summary

Redis persistence keeps your data safe across restarts.

RDB saves snapshots at intervals, good for fast backups.

AOF logs every change, good for minimal data loss.