2015-06-10 46 views
0

我使用redis如何更改redis以執行

我希望數據庫能夠持久化,但是當我殺掉我的進程時,我注意到數據沒有恢復。

在例子中,我有100個鍵和值。我的進程ID運行= 26060.當我這樣做:

kill -9 26060 

,並再次運行redis-server,所有的按鍵都將丟失。

我檢查redis.conf中的相關定義,但沒有找到任何東西。

我該如何讓它持久?

回答

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/ 
+0

我等待24小時。我使用redis 3. – MiddleWare

+1

添加到此答案中,您還可以使用命令「bgsave」觸發保存 http://redis.io/commands/bgsave –

+0

@MiddleWare您是否看到dump.rdb文件在「目錄」配置中指定的目錄? '/ var/lib/redis /'中的 – Geoffroy