1. Blocking snapshot
SAVE writes an RDB snapshot synchronously, blocking the server until it finishes.
SAVETyporithm · medium
Step 1 of 8 · intro card
Persistence & Scale
RDB takes point-in-time snapshots (compact, fast restart, but can lose recent writes); SAVE blocks while BGSAVE forks a child. AOF logs every write for stronger durability, enabled with appendonly yes and compacted by BGREWRITEAOF. LASTSAVE reports the last snapshot time. Many deployments run both.
RDB persistence saves a point-in-time snapshot of the dataset to disk. Snapshots are compact and restart fast, but any writes since the last snapshot are lost on a crash. SAVE writes the snapshot synchronously and blocks the server, while BGSAVE forks a child process so clients keep being served.
AOF (append-only file) persistence logs every write command, giving much better durability than periodic snapshots. You enable it with CONFIG SET appendonly yes. Because the log grows with every write, BGREWRITEAOF rebuilds a minimal AOF that reproduces the current state.
LASTSAVE returns the timestamp of the last successful RDB save, handy for checking how stale a snapshot is. Many production setups run RDB and AOF together: RDB for fast restarts and backups, AOF for minimal data loss.
RDB = point-in-time snapshot; SAVE blocks, BGSAVE forks.
AOF logs every write; enable with appendonly yes.
BGREWRITEAOF compacts the AOF log.
SAVE
BGSAVE
CONFIG SET appendonly yes
BGREWRITEAOF
LASTSAVEConnect each part of the code to the concept before you type.
SAVE writes an RDB snapshot synchronously, blocking the server until it finishes.
SAVEBGSAVE forks a child process to write the RDB snapshot without blocking client commands.
BGSAVESetting appendonly yes turns on the append-only file, which logs every write for better durability.
CONFIG SET appendonly yesBGREWRITEAOF rebuilds a compact AOF from the current dataset so the log does not grow unbounded.
BGREWRITEAOFLASTSAVE returns the Unix timestamp of the last successful RDB save.
LASTSAVERead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.