###1.下載安裝後,如何正確的啓動redis 直接雙擊是很差的,由於沒有指定配置文件,採用默認的配置,所以最好的作法是啓動的同時指定配置文件。這就不奇怪,我在Windows中修改了n遍config文件卻一直不生效。更噁心的是,安裝結束後由兩個配置文件,還不知道哪一個是,原來是啓動的時候選擇的。redis
C:\Program Files\Redis>redis-server.exe redis.windows.conf
###2.正確的配置持久化的文件名 默認是有個持久化策略的,至於具體啥問題也不去研究。我就是用來作存儲的,不出問題就行。真是糟糕的學習方式,土地主通常。 在配置持久化文件的時候有兩個配置項:windows
# The filename where to dump the DB dbfilename db\dump.rdb # The working directory. # # The DB will be written inside this directory, with the filename specified # above using the 'dbfilename' configuration directive. # # The Append Only File will also be created inside this directory. # # Note that you must specify a directory here, not a file name. dir D:\data\redis\
dbfilename
真的只是文件名,不要自做多情的覺得是相對路徑。因此上面的作法不對。應該是:ide
dbfilename dump.rdb
持久化的策略,默認是這樣的:學習
################################ 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
就是說,在900s內,一個key發生改變,則持久化到磁盤。相應的就是300s內10次改變,60s內10000次改變。因此,若是redis關掉了仍是會丟東西的。好比剛剛持久化到磁盤,你寫入了10個以上10000個一下的key,而後還不到300s,redi掛了,這些數據就麼了。this
順便記錄下持久化的日誌格式:.net
[5948] 06 Nov 13:54:05.270 # Server started, Redis version 3.0.501 [5948] 06 Nov 13:54:05.277 * The server is now ready to accept connections on port 6379 [5948] 06 Nov 13:59:06.064 * 10 changes in 300 seconds. Saving... [5948] 06 Nov 14:02:53.483 * Background saving started by pid 8460 [5948] 06 Nov 14:02:53.584 # fork operation complete [5948] 06 Nov 14:02:53.585 * Background saving terminated with success
其實早就應該看備份命令日誌
save bgsave
###參考code