Typorithm · medium

RDB & AOF

redis-rdb-aofredisrdbaofdurability
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn RDB & AOF

0%

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.

01

RDB = point-in-time snapshot; SAVE blocks, BGSAVE forks.

02

AOF logs every write; enable with appendonly yes.

03

BGREWRITEAOF compacts the AOF log.

SAVE
BGSAVE
CONFIG SET appendonly yes
BGREWRITEAOF
LASTSAVE

Read the implementation

Connect each part of the code to the concept before you type.

1. Blocking snapshot

SAVE writes an RDB snapshot synchronously, blocking the server until it finishes.

SAVE

2. Background snapshot

BGSAVE forks a child process to write the RDB snapshot without blocking client commands.

BGSAVE

3. Enable AOF

Setting appendonly yes turns on the append-only file, which logs every write for better durability.

CONFIG SET appendonly yes

4. Compact the log

BGREWRITEAOF rebuilds a compact AOF from the current dataset so the log does not grow unbounded.

BGREWRITEAOF

5. Last snapshot time

LASTSAVE returns the Unix timestamp of the last successful RDB save.

LASTSAVE

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

RDB & AOF: Lesson & Practice · Typorithm | ApplyDjinn