The difference between Redis and memcache is that Redis can persist data and support 5 types of data
So you can get a good look at the data persistence.
We installed the 2.6 version of Redis, and the RDB is turned on by default after installation
Data Persistence Sub-RDB and aof
Snapshot: (snapshotting) It writes the data of a certain moment to the hard disk
Append file only: (append-only file) He will copy the write command to the disk when he executes the command.
Snapshot (RDB):
Save 1 #900秒时间, at least one data update is saved to the data file
Save #300秒时间 with at least 10 updates to the data file
Save 10000 #60秒时间 with at least 10,000 updates to the data file
rdbcompression Yes #指定存储至本地数据库时是否压缩数据, the default is Yes,redis with LZF compression, if in order to save CPU time #可以关闭该选项, but will cause the database file flat huge
dbfilename Dump.rdb #指定rdb保存到本地数据库文件名
Stop-writes-on-bgsave-error Yes #当硬盘因为权限等原因无法写入时, stop writing
Rdbchecksum Yes #对rdb文件进行校验
There are 4 ways to create a snapshot:
1, the client executes Besave, the server fork a child process to write the snapshot to the hard disk, the parent process continues to process the write request
2, the client executes save, the server will not be in response to other commands before the creation of the snapshot, generally do not have enough memory to execute the besave of the case will go to execute save, generally do not use this
3, when the Redis server accepts a shutdown, or receives a standard term signal (kill), it executes a save, blocks the client request, and then shuts down the service after the save is executed.
4, as a Redis master-slave (see my other blog, Redis master-Slave synchronization)
Personal feeling if the data is kept in a particularly high demand, do not use the RDB can be used AOF
Append file Only (AOF):
#AppendOnly No # whether to log after each update operation, turn on enable AOF .
# Appendfsync always: Represents a manual call to Fsync () to write data to disk after each update operation (slow, secure, preferably don't use this will damage the hard drive)
#Appendfsync everysec # everysec: Indicates synchronization once per second (trade-offs, default values)
#Appendfsync No #: Indicates that the data cache of the operating system is synchronized to disk (fast) \
#
#Auto-aof-rewrite-percentage
#Auto-aof-rewrite-min-size 64MB
Redis executes bgrewriteaof when the AOF volume is greater than 64MB, and the volume of the aof file is greater than at least one time after the last rewrite (100%)
no- appendfsync-on-rewrite No #如下面的解释
bgrewriteaof mechanism, AOF is overridden in a subprocess, which does not block the processing of the remaining commands by the main process, and resolves the problem of aof file too large.
Now the problem has arisen, While performing the bgrewriteaof operation and the main process write AoF file, both operate the disk, and bgrewriteaof often involves a lot of disk operations, which will cause the main process to write aof files when the blocking situation, Now the No-appendfsync-on-rewrite parameter is on the exit. If this parameter is set to No, it is the safest way to not lose data, but to tolerate blocking problems. If it is set to Yes? This is equivalent to setting Appendfsync to no, which means that there is no disk operation, only a buffer is written, so this does not cause blocking (because there are no competing disks), but if Redis hangs up at this time, it loses data. How much data is lost? Up to 30s of data will be lost under the default settings for Linux operating systems.
Therefore, if the application is unable to tolerate a delay and can tolerate a small amount of data loss, it is set to Yes. Set to No if the application is unable to tolerate data loss
This article from "Wang Xiao Acid" blog, reproduced please contact the author!
Data persistence for Redis