我使用redis
。
我希望数据库能够持久化,但是当我终止我的进程时,我注意到数据没有恢复。
在示例中,我有100个键和值。我的进程在id = 26060上运行。当我这样做时:
kill -9 26060
再次运行redis-server
,所有密钥都丢失了。
我在redis.conf中查看相关定义,但找不到任何内容。
如何让它持久?
答案 0 :(得分:3)
关于您的测试,如果您希望对其进行快照,则应该等待5分钟才能终止该进程。
这是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
关于持久性的一切都在documentation
中解释将保存数据的文件由以下配置选项定义:
# 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/