文章出處



文章列表
Redis持久化功能
Redis為了內部數據的安全考慮,會把本身的數據以文件形式保存到硬盤中一份,在服務器重啟之后會自動把硬盤的數據恢復到內存(redis)的里邊。
數據保存到硬盤的過程就稱為“持久化”效果。
1. snap shotting快照持久化
該持久化默認開啟,一次性把redis中全部的數據保存一份存儲在硬盤中,如果數據非常多(10-20G)就不適合頻繁進行該持久化操作。
下方是快照持久化在本地硬盤保留的數據備份文件(redis自動生成):
查看快照持久化的備份頻率(打開redis.conf):
- ################################ 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 at all commenting all the "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
save 900 1 #900 秒內如果超過 1 個 key 被修改,則發起快照保存
save 300 10 #300秒超過10個key被修改,發起快照
save 60 10000 #60秒超過10000個key被修改,發起快照
以上三個save的理解:
數據修改的頻率非常高,備份的頻率也高
數據修改的頻率低,備份的頻率也低
查看快照持久化文件的名字和存儲位置(打開redis.conf):
- # The filename where to dump the DB
- dbfilename 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 ./
快照持久化 和 精細持久化 可以盡最大程度保證數據的安全:
2、手動發起快照持久化
手動發起快照持久化
文章列表
全站熱搜