Understanding Redis Persistence: RDB vs AOF Explained
Redis offers two persistence strategies—RDB snapshots and AOF command logging—each with distinct generation methods, configuration options, and recovery processes, allowing users to balance speed, safety, and data durability based on workload requirements.
Redis provides two persistence mechanisms: RDB and AOF.
RDB (Redis Database Backup)
RDB creates a compressed binary snapshot of the in‑memory dataset and saves it to disk. The snapshot can be generated manually with SAVE (blocking) or BGSAVE (non‑blocking child process), or automatically via the save configuration option, which triggers a BGSAVE when any of the defined time‑and‑change thresholds are met (e.g., 900 seconds with at least 1 change, 300 seconds with 10 changes, 60 seconds with 10 000 changes).
AOF (Append‑Only File)
AOF records every write command to a log file, similar to MySQL binlog. The file can be flushed to disk using three policies:
appendfsync always – fsync after every command (slow but safest).
appendfsync everysec – fsync every second (fast, may lose up to one second of data).
appendfsync no – rely on the operating system (fastest, least safe).
The default and recommended setting is appendfsync everysec, offering a balance between performance and durability.
Data Recovery
When Redis starts, it automatically loads an existing RDB file if present; the server blocks until the load completes. If AOF is enabled, Redis loads and replays the AOF file by reading each command, creating a simulated client, and executing the commands sequentially. When both RDB and AOF are enabled, AOF takes precedence during recovery.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
