0
0
Redisquery~10 mins

Redis persistence overview (RDB, AOF) - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Redis persistence overview (RDB, AOF)
Start Redis Server
Data in Memory
RDB Snapshot
Save to Disk
Data Persistence
Recovery on Restart
Redis keeps data in memory and saves it to disk using two methods: RDB snapshots and AOF logs, which help recover data after restart.
Execution Sample
Redis
SET key1 value1
SET key2 value2
SAVE
APPEND command: SET key3 value3
RESTART
LOAD data from RDB and AOF
This sequence shows setting keys, saving snapshot (RDB), appending commands (AOF), restarting Redis, and loading data from persistence files.
Execution Table
StepActionRDB StateAOF StateResult
1SET key1 value1Memory updatedAOF emptykey1 in memory
2SET key2 value2Memory updatedAOF emptykey2 in memory
3SAVE (RDB snapshot)RDB file saved with key1, key2AOF emptyDisk has snapshot
4APPEND command: SET key3 value3RDB unchangedAOF file has SET key3AOF logs new command
5RESTART RedisLoad RDB fileReplay AOF commandsMemory restored with key1, key2, key3
6ENDData loadedData loadedRedis ready with all keys
💡 Redis stops loading after replaying all AOF commands and loading RDB snapshot
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
Memory Data{}{"key1":"value1"}{"key1":"value1","key2":"value2"}{"key1":"value1","key2":"value2"}{"key1":"value1","key2":"value2","key3":"value3"}{"key1":"value1","key2":"value2","key3":"value3"}{"key1":"value1","key2":"value2","key3":"value3"}
RDB FileNoneNoneSnapshot with key1,key2Snapshot with key1,key2Snapshot with key1,key2Loaded snapshotLoaded snapshot
AOF FileEmptyEmptyEmptyContains SET key3Contains SET key3Replayed commandsReplayed commands
Key Moments - 2 Insights
Why does Redis load both RDB and AOF files on restart?
Redis first loads the RDB snapshot to restore a baseline, then replays AOF commands to apply recent changes not in the snapshot, as shown in execution_table steps 5 and 6.
What happens if SAVE is not called before appending AOF commands?
Without SAVE, the RDB file is outdated or missing, so Redis relies on AOF to restore data. The execution_table shows RDB unchanged at step 4, meaning AOF holds newer data.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what does the RDB file contain?
ASnapshot with key1 and key2
BNo data, it's empty
CSnapshot with key3 only
DAll keys including key3
💡 Hint
Check the 'RDB State' column at step 3 in execution_table
At which step does the AOF file start containing data?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'AOF State' column in execution_table to see when it changes from empty
If Redis restarts without an AOF file, what will happen according to the flow?
AData will be lost completely
BData will be restored from RDB snapshot only
CRedis will fail to start
DRedis will create a new empty database
💡 Hint
Refer to concept_flow where RDB snapshot is loaded first on restart
Concept Snapshot
Redis persistence saves data from memory to disk.
RDB creates snapshots at intervals.
AOF logs every write command.
On restart, Redis loads RDB then replays AOF.
RDB is fast but less frequent.
AOF is slower but more complete.
Full Transcript
Redis stores data in memory for fast access. To keep data safe after a restart, it uses two methods: RDB snapshots and AOF logs. RDB snapshots save the whole dataset at once, like taking a photo. AOF logs every change command, like a diary. When Redis restarts, it loads the snapshot first, then replays the commands from the log to recover the latest data. This way, Redis balances speed and data safety.