Question: How long does Redis store data?


Redis is an in-memory data store that can persist data to disk. The persistence options in Redis are:

  1. RDB (Redis Database File): This option saves a snapshot of the dataset at specified intervals. By default, a snapshot is taken every 900 seconds (15 minutes) if at least one key has changed, and at least 5 minutes have elapsed since the last snapshot. You can configure this behavior by modifying the save directive in the Redis configuration file. Redis uses a background process to save the snapshot to disk, which means that there is no blocking when the snapshot is taken.

  2. AOF (Append-Only File): This option logs all write operations to a file, which can be played back to reconstruct the dataset. The AOF file can be configured to sync after every write operation, or after a specified number of write operations or bytes. AOF is slower than RDB but provides better durability guarantees.

In general, Redis stores data indefinitely as long as it is not explicitly deleted or evicted due to memory constraints. However, the amount of time that data is persisted to disk depends on the persistence option(s) you have configured. If neither RDB nor AOF persistence is enabled, then Redis will only hold data in memory until it runs out of space, at which point it will start evicting keys based on the eviction policy you have configured.

Here's an example of configuring both RDB and AOF persistence in Redis (in the redis.conf file):

# enable RDB persistence
save 900 1          # save after 900 seconds if 1 or more keys changed
save 300 10         # save after 300 seconds if 10 or more keys changed
save 60 10000       # save after 60 seconds if 10000 or more keys changed

# enable AOF persistence
appendonly yes      # enable the AOF log
appendfilename "appendonly.aof"   # filename for the AOF log
appendfsync everysec             # sync the AOF log to disk every second
Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.