Redis data is not persistent

1.3k views Asked by At

I am new to using Redis and I am playing around a little bit with it. I have noticed that after a little time, let's say 10 minutes all the keys that I inserted just go away. I just did the default installation showed in the documentation. I didn't configure anything with a redis.config. Is there any configuration that I need to do so my data can persist?

Environment

Redis Server

Redis server v=6.2.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=557672d61c1e18ba

Redis-cli

redis-cli 6.2.6

Ubuntu 18.08 VM. I have also been using redisInsight to insert the keys.

1

There are 1 answers

1
Shoobi On

there are two mechanisms for persisting the data to disk:

  1. snapshotting
  2. append-only file (aof)

if you want to use snapshotting, you need to add the following settings in redis.conf file

  • dir ./path_for_saving_snapshot
  • dbfilename "name_of _snapshot.rdb"
  • save 60 1000

with this configuration, redis will dump the data to disk every 60 seconds if at least 1,000 keys changed in that period.

if you want to use aof, you need to add the following settings in redis.conf file

  • appendonly yes
  • appendfilename "your_aof_file.aof"
  • appendfsync everysecond

everysecond is the default FYSNC policy. you have also other options.

You can configure your Redis instance to use either of the two mechanisms or a combination of both.