Bird
Raised Fist0
Redisquery~10 mins

RDB snapshots (point-in-time) in Redis - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - RDB snapshots (point-in-time)
Start Redis Server
↓
Data changes in memory
↓
Trigger snapshot condition?
↓
Create RDB file
↓
Save point-in-time data
↓
Continue accepting commands
Redis saves a snapshot of data at a specific time when certain conditions are met, storing it in an RDB file for point-in-time recovery.
Execution Sample
Redis
SAVE
SET key1 value1
SET key2 value2
SAVE
DEL key1
SAVE
Shows Redis saving snapshots before and after data changes to capture point-in-time states.
Execution Table
StepCommandMemory Data StateRDB Snapshot CreatedSnapshot Content
1SAVE{}Yes{} (empty)
2SET key1 value1{key1: value1}No{} (previous snapshot)
3SET key2 value2{key1: value1, key2: value2}No{} (previous snapshot)
4SAVESame as memoryYes{key1: value1, key2: value2}
5DEL key1{key2: value2}No{key1: value1, key2: value2}
6SAVESame as memoryYes{key2: value2}
7ENDN/AN/AN/A
💡 No more commands; snapshots capture data state at SAVE commands.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6Final
Memory Data{}{}{key1: value1}{key1: value1, key2: value2}{key1: value1, key2: value2}{key2: value2}{key2: value2}{key2: value2}
RDB Snapshot{}{}{}{}{key1: value1, key2: value2}{key1: value1, key2: value2}{key2: value2}{key2: value2}
Key Moments - 3 Insights
Why does the RDB snapshot not change immediately after SET commands?
Because Redis only saves snapshots when the SAVE command runs, not on every data change. See steps 2 and 3 in execution_table where memory changes but snapshot stays the same.
What does the snapshot represent at each SAVE?
It represents the exact data state in memory at the moment SAVE runs, capturing a point-in-time copy. See steps 1, 4, and 6 where snapshots reflect memory at those times.
Why is the snapshot still the old data after DEL before the next SAVE?
Because the snapshot file only updates on SAVE, so deleting keys in memory doesn't affect the snapshot until the next SAVE command. See step 5 vs step 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4, what data is saved in the RDB snapshot?
A{}
B{key2: value2}
C{key1: value1, key2: value2}
D{key1: value1}
💡 Hint
Check the 'Snapshot Content' column at step 4 in execution_table.
At which step does the snapshot first include key2?
AStep 2
BStep 4
CStep 3
DStep 6
💡 Hint
Look at when the RDB snapshot content changes to include key2 in execution_table.
If the DEL command was followed immediately by a SAVE, what would the snapshot contain?
A{key2: value2}
B{key1: value1, key2: value2}
C{}
D{key1: value1}
💡 Hint
Refer to step 5 and 6 in execution_table and variable_tracker for memory and snapshot states.
Concept Snapshot
RDB snapshots save Redis data at a specific time.
Triggered by SAVE or automatic conditions.
Snapshot files store point-in-time data.
Data changes in memory do not update snapshots until saved.
Useful for backups and recovery.
Full Transcript
Redis RDB snapshots capture the exact data state at a specific moment. When Redis runs the SAVE command, it writes the current in-memory data to a snapshot file. Data changes like SET or DEL commands update memory immediately but do not affect the snapshot until the next SAVE. This allows Redis to have point-in-time backups. The execution trace shows memory data changing step-by-step and snapshots created only when SAVE runs, reflecting the data at that time. This helps beginners understand how snapshots represent frozen moments of data, not live updates.

Practice

(1/5)
1. What is the primary purpose of an RDB snapshot in Redis?
easy
A. To increase the speed of Redis commands
B. To save the current state of the database at a specific point in time
C. To permanently delete all data from Redis
D. To replicate data to another Redis instance in real-time

Solution

  1. Step 1: Understand what RDB snapshots do

    RDB snapshots capture the exact data stored in Redis at a certain moment, creating a backup file.
  2. Step 2: Compare options with snapshot purpose

    Only To save the current state of the database at a specific point in time describes saving the database state at a point in time, which matches the snapshot function.
  3. Final Answer:

    To save the current state of the database at a specific point in time -> Option B
  4. Quick Check:

    RDB snapshot = point-in-time save [OK]
Hint: Snapshots save data state at one moment, like a photo [OK]
Common Mistakes:
  • Confusing snapshots with real-time replication
  • Thinking snapshots delete data
  • Assuming snapshots speed up commands
2. Which Redis command creates an RDB snapshot immediately and blocks the server until done?
easy
A. SAVE
B. BGSAVE
C. RESTORE
D. FLUSHDB

Solution

  1. Step 1: Recall Redis commands for snapshots

    SAVE blocks Redis and saves the snapshot immediately; BGSAVE saves in background without blocking.
  2. Step 2: Match command to blocking immediate save

    Only SAVE matches the description of immediate blocking snapshot creation.
  3. Final Answer:

    SAVE -> Option A
  4. Quick Check:

    Immediate blocking snapshot = SAVE [OK]
Hint: SAVE blocks Redis to save snapshot immediately [OK]
Common Mistakes:
  • Choosing BGSAVE which is non-blocking
  • Confusing RESTORE with saving snapshots
  • Thinking FLUSHDB saves data
3. Given the following Redis commands executed in order:
BGSAVE
SET key1 value1
SAVE
SET key2 value2

Which keys will be present in the RDB snapshot created by the SAVE command?
medium
A. Neither key1 nor key2
B. Only key2
C. Only key1
D. Both key1 and key2

Solution

  1. Step 1: Understand timing of BGSAVE and SAVE

    BGSAVE starts background save but does not block; SET key1 happens after BGSAVE starts, so key1 may or may not be in that snapshot.
  2. Step 2: SAVE blocks and saves immediately after SET key1

    SAVE runs after SET key1 but before SET key2, so the snapshot from SAVE includes key1 but not key2.
  3. Final Answer:

    Only key1 -> Option C
  4. Quick Check:

    SAVE snapshot = keys before SAVE command [OK]
Hint: SAVE snapshot includes keys set before it runs [OK]
Common Mistakes:
  • Assuming BGSAVE snapshot includes key1 for sure
  • Thinking SAVE snapshot includes key2 set after it
  • Confusing background and immediate saves
4. You run the command BGSAVE but receive an error: "Background save already in progress". What is the best way to fix this?
medium
A. Run FLUSHALL to clear all data and then run BGSAVE
B. Restart the Redis server to clear the background save
C. Run SAVE instead to block and save immediately
D. Wait for the current background save to finish before running BGSAVE again

Solution

  1. Step 1: Understand the error cause

    The error means a background save is already running; Redis does not allow multiple concurrent BGSAVE commands.
  2. Step 2: Choose the proper fix

    Waiting for the current BGSAVE to finish is the correct approach; running SAVE blocks but is not necessary, restarting or flushing data is extreme and unnecessary.
  3. Final Answer:

    Wait for the current background save to finish before running BGSAVE again -> Option D
  4. Quick Check:

    Only one BGSAVE at a time allowed [OK]
Hint: Only one BGSAVE runs at once; wait before retrying [OK]
Common Mistakes:
  • Restarting server unnecessarily
  • Running SAVE without need
  • Flushing data to fix save error
5. You want to ensure Redis creates an RDB snapshot every 5 minutes only if at least 100 keys changed. Which configuration snippet correctly sets this behavior in redis.conf?
hard
A. save 300 100
B. save 100 300
C. save 5 100
D. save 300 5

Solution

  1. Step 1: Understand Redis save syntax

    The syntax is save <seconds> <changes>, meaning save if at least <changes> keys changed in <seconds> seconds.
  2. Step 2: Match 5 minutes and 100 changes

    5 minutes = 300 seconds, so save 300 100 means save every 300 seconds if 100 keys changed.
  3. Final Answer:

    save 300 100 -> Option A
  4. Quick Check:

    save seconds changes = save 300 100 [OK]
Hint: save syntax: save seconds changes (time then count) [OK]
Common Mistakes:
  • Swapping seconds and changes values
  • Using minutes instead of seconds
  • Misunderstanding save triggers
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard