How change redis to be persistent

1k Views Asked by At

I use redis.

I want that the DB will be persistent, but when I kill my process, I notice that the data doesn't recover.

In example, I have 100 keys and values. my process run on id = 26060. When I do:

kill -9 26060

and run redis-server again, all the keys are lost.

I check relevant definition in redis.conf, but don't find anything.

How can I make it persistent?

1

There are 1 best solutions below

9
On BEST ANSWER

Regarding your test, you should wait 5 minutes before killing the process if you want it to be snapshotted.

This is the default config for Redis (2.8 - 3.0):

################################ SNAPSHOTTING  ################################
#
# Save the DB on disk:
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#
#   Note: you can disable saving completely by commenting out all "save" lines.
#
#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#
#   save ""

save 900 1
save 300 10
save 60 10000

Everything about persistence is explained in the documentation

The file where the data will be saved is defined by the following configuration options:

# The filename where to dump the DB
dbfilename dump.rdb

# For default save/load DB in/from the working directory
# Note that you must specify a directory not a file name.
dir /var/lib/redis/