Redis learning [seven] data persistence

Redis data persistence in two ways. RDB and AOF.

1、RDB

RDB is a snapshot of the way through the process of persistence. Specific conditions of win, a snapshot of the data will be in memory to the hard disk. RDB snapshot of the following conditions

1.1, redis.conf configuration file (windows file is redis.windows-service.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 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 ""    设置为空是不开RDB

save 900 1        900秒内,有一个key更改就触发快照
save 300 10       300秒内,有10个key更改就触发快照
save 60 10000     60秒内有10000个key更改。触发快照
# The filename where to dump the DB
dbfilename dump.rdb     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 ./                  保存的路径

Redis serve as side information in the windows operating system

 As it can be seen a save operation performed in 3600 seconds

1.2, the implementation of save bgsave

1.3, okay flushall

 

2、AOF

AOF is every redis commands are written to disk

############################## APPEND ONLY MODE ###############################

# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information.

appendonly no       AOF持久化开关

# The name of the append only file (default: "appendonly.aof")
appendfilename "appendonly.aof"       文件名
# The fsync() call tells the Operating System to actually write data on disk
# instead of waiting for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log . Slow, Safest.
# everysec: fsync only one time every second. Compromise.
#
# The default is "everysec", as that's usually the right compromise between
# speed and data safety. It's up to you to understand if you can relax this to
# "no" that will let the operating system flush the output buffer when
# it wants, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting),
# or on the contrary, use "always" that's very slow but a bit safer than
# everysec.
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".

# appendfsync always           每个命令都执行同步
appendfsync everysec           每秒同步
# appendfsync no               不同步

Contents aof file

 3, the difference RDB and the AOF

RDB persistence means that within a specified time interval memory snapshot of the data set is written to disk, the actual operation is fork a child process, the first set of data written to a temporary file, write successfully, and then replace the file before , binary compressed storage.

 AOF persisted in the form of log records processed by the server every write, delete, query operation is not recorded, the recorded text, you can open the file to see the detailed operating record.

The figure we can extract the following information

1, RDB embodiment persistent data smaller than AOF, AOF Redis each instruction needs to be written to the persistent medium.

2, RDB contrast AOF, a greater risk of losing data. Within the backup interval server downtime.

3, AOF than RDB data recovery takes longer.

 

Published 22 original articles · won praise 9 · views 8813

Guess you like

Origin blog.csdn.net/ljm_c_bok/article/details/104924969