0
0
Redisquery~5 mins

RDB vs AOF comparison in Redis

Choose your learning style9 modes available
Introduction

RDB and AOF are two ways Redis saves data to keep it safe. They help recover data if Redis stops or crashes.

You want fast recovery with less disk space use.
You need to save data very often to avoid losing recent changes.
You want a balance between performance and data safety.
You want to understand how Redis saves data to choose the best method.
You want to troubleshoot or optimize Redis persistence.
Syntax
Redis
RDB: Saves snapshots of data at intervals.
AOF: Logs every write operation to a file.

RDB creates a point-in-time snapshot of the database.

AOF records each command that changes the data, like a diary.

Examples
RDB example: Save snapshot if 1 change in 900 seconds, or 10 changes in 300 seconds, etc.
Redis
save 900 1
save 300 10
save 60 10000
AOF example: Turn on AOF and sync to disk every second for safety.
Redis
appendonly yes
appendfsync everysec
Sample Program

This config saves snapshots at intervals and also logs every write command every second.

Redis
# This is a Redis config snippet showing RDB and AOF settings
save 900 1
save 300 10
save 60 10000
appendonly yes
appendfsync everysec
OutputSuccess
Important Notes

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

AOF is safer for data but can be slower and use more disk space.

You can use both together for better safety and performance.

Summary

RDB saves snapshots at intervals, good for fast recovery.

AOF logs every change, good for data safety.

Choosing depends on your needs for speed and data safety.