Redis persistence is available in two types: RDB and AOF, and the default is RDB persistence configuration
RDB records operations over a period of time, and the configuration of a disk is persisted after more than a period of operation. AOF enables persistence of every operation.
Snapshot persistence mode
Snapshots are the default way to persist. This method is to write the data in memory as a snapshot into a binary, and the default file name is dump.rdb. You can configure the snapshot persistence method automatically. We can configure redis to automatically take snapshots if more than m keys are modified within n seconds, the following is the default snapshot saving configuration
save 900 1 #900秒内如果超过1个key被修改, the snapshot save is initiated save 300 10 #300秒内容如超过10个key被修改, the snapshot save is initiated save 60 10000
AOF persistence mode
To configure the method, open the Redis configuration file. Find AppendOnly. The default is appendonly no. Changed to appendonly yes. Options:
1、appendfsync no
When appendfsync is set to no, Redis will not actively call fsync to synchronize the AOF log content to disk, so it all depends entirely on the debugging of the operating system. For most Linux operating systems, fsync is done every 30 seconds to write data from the buffer to disk.
2、appendfsync everysec
When appendfsync is set to everysec, Redis will make an fsync call every second by default to write the data in the buffer to disk. However, when the fsync call lasts more than 1 second. Redis will take the policy of delaying fsync and wait another second. That is, fsync is performed after two seconds, and this time fsync will be performed no matter how long it will be executed. At this time, the current write operation will be blocked because the file descriptor will be blocked during fsync.
So, the bottom line is: in most cases, Redis will fsync every second. In the worst case, an fsync operation will occur every two seconds.
This operation is called group commit in most database systems, which is the combination of data from multiple write operations and writes the log to disk at once.
3、appednfsync always
When appendfsync is set to always, fsync is called once for every write operation, when the data is the most secure, and of course, its performance is also affected because fsync is performed every time
Appendfsync everysec is recommended (default)
Snapshot mode can be enabled at the same time as AOF mode, do not affect each other
Redis turns off persistence
Data persistence is a feature that sets Redis apart from other caches, and has obvious advantages. But if I don't want Redis to persist the data now, I just want to use it as a cache, just like memcache cache. I looked it up on the Internet, and it all introduced how to turn on Redis persistence, and there was very little content on how to turn off persistence.
Modify the configuration file Comment all the save configuration information in the configuration file as follows:
Or modify the configuration file as follows:
After the modification is completed, restart the Redis service.
Execute the action command Syntax:
After executing the command, it takes effect without restarting the service.
|