Configure Redis for Combined RDB and AOF Persistence
📖 Scenario: You are managing a Redis server that needs to be reliable and fast. To ensure data safety, you want to use both RDB snapshots and AOF (Append Only File) logging together.
🎯 Goal: Configure Redis to save data using both RDB snapshots and AOF logging for better durability and recovery.
📋 What You'll Learn
Create a Redis configuration file named redis.conf.
Enable RDB snapshotting with a save interval of 60 seconds if at least 100 changes occur.
Enable AOF persistence with the appendfsync policy set to every second.
Set the AOF rewrite policy to trigger when the AOF file size is at least twice the size of the rewritten file.
Ensure the configuration file includes both RDB and AOF settings correctly.
💡 Why This Matters
🌍 Real World
Many production Redis servers use combined RDB and AOF persistence to balance performance and data safety.
💼 Career
Knowing how to configure Redis persistence is essential for roles like DevOps engineers, backend developers, and system administrators.
Progress0 / 4 steps
1
Create the Redis configuration file with RDB snapshot settings
Create a file named redis.conf and add the RDB snapshot setting save 60 100 to save the DB every 60 seconds if at least 100 keys changed.
Redis
Hint
The save directive controls RDB snapshot intervals. Use save 60 100 to save every 60 seconds if 100 changes happened.
2
Enable AOF persistence with appendfsync every second
In redis.conf, add the line appendonly yes to enable AOF, and set appendfsync everysec to sync the AOF file every second.
Redis
Hint
Use appendonly yes to turn on AOF and appendfsync everysec to write changes to disk every second.
3
Set AOF rewrite policy to trigger at twice the rewritten file size
Add the line auto-aof-rewrite-percentage 100 and auto-aof-rewrite-min-size 64mb to redis.conf so AOF rewrites when the file grows 100% larger than the last rewrite and is at least 64 megabytes.
Redis
Hint
The auto-aof-rewrite-percentage sets the growth percentage to trigger rewrite. The auto-aof-rewrite-min-size sets the minimum file size for rewrite.
4
Confirm the combined RDB and AOF configuration
Ensure redis.conf contains all these lines: save 60 100, appendonly yes, appendfsync everysec, auto-aof-rewrite-percentage 100, and auto-aof-rewrite-min-size 64mb.
Redis
Hint
Double-check all required lines are in the config file to enable combined RDB and AOF persistence.
Practice
(1/5)
1. What is the main advantage of using both RDB and AOF persistence together in Redis?
easy
A. It disables data persistence to improve speed.
B. It combines fast startup with high data durability.
C. It reduces memory usage significantly.
D. It automatically compresses all data files.
Solution
Step 1: Understand RDB persistence
RDB creates snapshots periodically, allowing Redis to start quickly by loading a compact file.
Step 2: Understand AOF persistence
AOF logs every write operation, ensuring data durability by replaying commands after a restart.
Final Answer:
It combines fast startup with high data durability. -> Option B
Quick Check:
Combined RDB + AOF = Fast startup + durability [OK]
2. Which Redis configuration option enables both RDB snapshots and AOF persistence?
easy
A. appendonly yes and save ""
B. appendonly no and save ""
C. save no and appendonly no
D. appendonly yes and save 900 1
Solution
Step 1: Identify RDB snapshot setting
The 'save 900 1' means save snapshot if at least 1 change in 900 seconds.
Step 2: Identify AOF setting
'appendonly yes' enables AOF persistence logging every write.
Final Answer:
appendonly yes and save 900 1 -> Option D
Quick Check:
Enable both RDB and AOF with save + appendonly yes [OK]
Hint: Look for appendonly yes plus save with time/count [OK]
Common Mistakes:
Setting appendonly no disables AOF
Empty save disables RDB snapshots
Confusing syntax for save option
3. Given Redis is configured with both RDB and AOF enabled, what happens if Redis crashes after some writes but before the next RDB snapshot?
medium
A. Data is restored from AOF log, including recent writes after last snapshot.
B. Data is restored from the last snapshot only, losing recent writes.
C. Redis starts empty with no data restored.
D. Redis merges partial snapshot and AOF, causing data duplication.
Solution
Step 1: Understand RDB snapshot timing
RDB snapshots happen periodically, so recent writes after last snapshot are not saved there.
Step 2: Understand AOF recovery
AOF logs every write, so Redis replays AOF to restore all writes including recent ones.
Final Answer:
Data is restored from AOF log, including recent writes after last snapshot. -> Option A
Quick Check:
AOF recovers recent writes missed by RDB [OK]
Hint: AOF logs all writes; RDB snapshots periodically [OK]
Common Mistakes:
Assuming only RDB restores data
Thinking Redis starts empty after crash
Believing Redis merges snapshot and AOF causing duplicates
4. You enabled both RDB and AOF in Redis, but after a restart, some recent data is missing. What is the most likely cause?
medium
A. Redis does not support combined persistence.
B. RDB snapshot interval was set to zero.
C. AOF file was corrupted or disabled during restart.
D. The Redis server was started with wrong port.
Solution
Step 1: Check AOF role in recovery
AOF logs all writes and is used to restore recent data after restart.
Step 2: Identify cause of missing recent data
If AOF is corrupted or disabled, recent writes after last snapshot are lost.
Final Answer:
AOF file was corrupted or disabled during restart. -> Option C
Quick Check:
Missing recent data usually means AOF problem [OK]
Hint: Check AOF file integrity if recent data missing after restart [OK]
Common Mistakes:
Assuming Redis can't combine RDB and AOF
Ignoring AOF file corruption possibility
Blaming wrong port for data loss
5. You want to optimize Redis persistence by combining RDB snapshots every 15 minutes and AOF with 'everysec' fsync policy. Which statement is true about this setup?
hard
A. This setup balances fast recovery and durability with minimal performance impact.
B. This setup disables AOF fsync, risking data loss on crash.
C. RDB snapshots every 15 minutes cause Redis to block all writes during save.
D. AOF with 'everysec' fsync writes data to disk after every command synchronously.
Solution
Step 1: Understand RDB snapshot interval
Snapshots every 15 minutes reduce blocking frequency and provide periodic backups.
Step 2: Understand AOF 'everysec' fsync
'everysec' fsync writes AOF to disk every second asynchronously, balancing durability and performance.
Step 3: Combine effects
This combination offers fast recovery from snapshots and durability from AOF with low performance cost.
Final Answer:
This setup balances fast recovery and durability with minimal performance impact. -> Option A
Quick Check:
RDB + AOF everysec = balanced durability and speed [OK]
Hint: Use RDB for snapshots, AOF everysec for durability and speed [OK]
Common Mistakes:
Thinking 'everysec' fsync is synchronous after every command
Assuming RDB snapshots block Redis for long every time
Believing this setup disables AOF durability
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.