Difficulty: Intermediate
Should you keep RDB compression enabled in Redis? What does it compress, what does it cost, and when might you turn it off?
Yes, in almost all cases. rdbcompression yes is the default and makes Redis compress string data in RDB snapshots with LZF, a very fast compression algorithm. It usually shrinks snapshot files noticeably, which speeds up disk writes, backups and full resyncs to replicas, at the cost of a little CPU in the background process that writes the snapshot.
How much you save depends on the data. Repetitive JSON, HTML fragments and text compress well; already compressed or random data (images, encrypted tokens, protobuf) barely shrinks.
Snapshots are produced by BGSAVE, which forks a child process. The child walks the dataset and does the compression, so the main thread serving clients is not blocked by it. The costs are:
On a host with spare cores this is negligible compared to the I/O saved.
zstd before shipping it to object storage.Measure before changing it: compare snapshot size and rdb_last_bgsave_time_sec from INFO persistence with the setting on and off.
| Setting | Default | Purpose |
|---|---|---|
rdbcompression | yes | LZF-compress strings in RDB |
rdbchecksum | yes | Append a CRC64 checksum to detect corruption, small cost on save and load |
save | snapshot rules such as 3600 1 300 100 60 10000 | When to run BGSAVE automatically |
stop-writes-on-bgsave-error | yes | Refuse writes if snapshots are failing |
The same RDB format is used for full replication syncs, including diskless replication (repl-diskless-sync), so compression also reduces the bytes sent to a new replica.
redis-cli CONFIG GET rdbcompression
redis-cli CONFIG GET rdbchecksum
# Take a snapshot and note its size and duration
redis-cli BGSAVE
redis-cli INFO persistence | grep -E 'rdb_last_bgsave_status|rdb_last_bgsave_time_sec'
ls -lh /var/lib/redis/dump.rdb
# Try without compression and compare
redis-cli CONFIG SET rdbcompression no
redis-cli BGSAVE
Compare the file size and rdb_last_bgsave_time_sec between the two runs. Remember to set rdbcompression back to yes, and persist the choice in redis.conf.
RDB snapshot, rdbcompression, LZF, rdbchecksum, Fork and BGSAVE