Redis
Persistence
Configure RDB snapshots and AOF append logs.
By EZ4Code Team
persistencerdbaof
Code
# redis.conf - RDB snapshots
save 900 1 # 1 change in 900s
save 300 10 # 10 changes in 300s
save 60 10000
dbfilename dump.rdb
dir /var/lib/redis
# AOF (Append Only File)
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec # always | everysec | no
# Manual commands
BGSAVE # async RDB snapshot
BGREWRITEAOF # compact AOF
LASTSAVE # timestamp of last save
DEBUG OBJECT key # internal info
# Mixing RDB + AOF gives best durability + recovery speed
# aof-use-rdb-preamble yes (RDB prefix in AOF)Explanation
Redis offers two persistence strategies: RDB snapshots for compact point-in-time backups and AOF for a log of every write command. RDB restarts faster, while AOF (with appendfsync everysec) loses at most one second of data. Combining both gives durability and fast recovery.
More Redis Snippets
Strings & Counters
Set, get, increment, and expire string values.
Lists & Queues
Build queues and stacks with list operations.
Hashes
Store object fields and values efficiently.
Sets
Manage unique collections and compute intersections.
Sorted Sets & Leaderboards
Rank items by score for leaderboards and scheduling.
Pub/Sub
Broadcast messages to subscribed clients.