Code Reference

Persistence

Redis · Reference cheat sheet

Persistence

Redis · Reference cheat sheet


📋 Overview

Redis can persist in-memory data via RDB snapshots, AOF logs, or both. Persistence improves durability but is not a substitute for backups and replication strategy.

🔧 Core concepts

ModeHow
RDBPoint-in-time .rdb snapshots
AOFAppend-only log of write commands
RDB+AOFCommon hybrid
No persistencePure cache (accept data loss)
KnobMeaning
saveRDB schedule
appendonlyEnable AOF
appendfsyncalways / everysec / no
ReplicaContinuity via replication

💡 Examples

Check persistence config:

redis-cli CONFIG GET save
redis-cli CONFIG GET appendonly

Manual save:

BGSAVE
LASTSAVE

AOF rewrite:

BGREWRITEAOF

⚠️ Pitfalls

  • appendfsync always is safest and slowest — usually everysec is the compromise.
  • Forking for BGSAVE on large datasets needs free memory headroom.
  • Restoring from outdated RDB after a crash still loses recent writes if AOF is off.

On this page