0
0
RedisHow-ToBeginner · 3 min read

How to Configure RDB Persistence in Redis for Data Durability

To configure RDB persistence in Redis, enable snapshotting by setting save directives in the redis.conf file. Redis will then save snapshots of your dataset to disk at specified intervals, creating .rdb files for data durability.
📐

Syntax

The main configuration for RDB persistence is done in the redis.conf file using the save directive. Each save line specifies when Redis should create a snapshot based on the number of seconds and the number of changes (writes) to the dataset.

  • save <seconds> <changes>: Save the DB if at least changes keys changed within seconds.
  • dbfilename <filename>: Name of the RDB file (default is dump.rdb).
  • dir <directory>: Directory where the RDB file is saved.
conf
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
dir /var/lib/redis
💻

Example

This example shows a Redis configuration snippet that saves a snapshot if at least 1 key changes in 900 seconds, or 10 keys change in 300 seconds, or 10000 keys change in 60 seconds. The snapshot is saved as dump.rdb in /var/lib/redis.

conf
# redis.conf snippet
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
dir /var/lib/redis
⚠️

Common Pitfalls

Common mistakes when configuring RDB persistence include:

  • Not setting any save directives, which disables snapshotting.
  • Setting intervals too long or changes too high, causing infrequent snapshots and risking data loss.
  • Incorrect dir path causing Redis to fail saving the RDB file.
  • Not restarting Redis after changing redis.conf, so changes don't take effect.

Always verify permissions on the snapshot directory and test persistence by restarting Redis and checking if data is restored.

📊

Quick Reference

DirectiveDescriptionExample
saveSets snapshot intervals based on seconds and changessave 900 1
dbfilenameSets the name of the RDB filedbfilename dump.rdb
dirSets the directory to save the RDB filedir /var/lib/redis

Key Takeaways

Enable RDB persistence by setting save directives in redis.conf.
Choose snapshot intervals balancing data safety and performance.
Set correct dir and dbfilename for saving snapshots.
Restart Redis after configuration changes to apply them.
Verify snapshot files exist and Redis restores data after restart.