Redis持久化功能
Redis爲了內部數據的安全考慮,會把自己的數據以文件形式保存到硬盤中一份,在服務器重啓以後會自動把硬盤的數據恢復到內存(redis)的裏邊。redis
數據保存到硬盤的過程就稱爲「持久化」效果。安全
1. snap shotting快照持久化
該持久化默認開啓,一次性把redis中所有的數據保存一份存儲在硬盤中,若是數據很是多(10-20G)就不適合頻繁進行該持久化操做。服務器
下方是快照持久化在本地硬盤保留的數據備份文件(redis自動生成):ide
查看快照持久化的備份頻率(打開redis.conf):post
- ################################ 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 被修改,則發起快照保存this
save 300 10 #300秒超過10個key被修改,發起快照spa
save 60 10000 #60秒超過10000個key被修改,發起快照內存
以上三個save的理解:ci
數據修改的頻率很是高,備份的頻率也高rem
數據修改的頻率低,備份的頻率也低
查看快照持久化文件的名字和存儲位置(打開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 ./
快照持久化 和 精細持久化 能夠盡最大程度保證數據的安全:
二、手動發起快照持久化
手動發起快照持久化