Yes, Redis can persist data in two ways:
Here's an example of how to configure snapshotting in Redis configuration file (redis.conf
):
save 900 1 # save after 900 seconds (15 min) if at least 1 key has changed
save 300 100 # save after 300 seconds (5 min) if at least 100 keys have changed
You can also take a snapshot manually by calling the BGSAVE
command or its blocking counterpart SAVE
. The former forks a child process to perform the snapshotting in the background, while the latter blocks all other Redis clients until the snapshot is complete.
Here's an example of how to configure AOF persistence in redis.conf
:
appendonly yes # enable AOF persistence
appendfsync always # sync AOF to disk after every write operation (safe, but slow)
There are three different modes for appendfsync
:
always
: sync after every write operation (safe, but slow)everysec
: sync every second (default option)no
: never sync, let the operating system handle it (fast, but risky)It's worth noting that AOF persistence can be slower and more resource-intensive than snapshotting, especially when the AOF file gets very large. However, it provides a more granular level of durability, as it logs every write operation to disk. If both snapshotting and AOF persistence are enabled, Redis will use the AOF to reconstruct the dataset if it exists, or fall back to the latest snapshot if not.
In conclusion, Redis can persist data through either snapshotting or AOF persistence, or both. Which method to choose depends on your particular use case and performance requirements.
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.