3. Persistence-related configuration in redis.conf

Source: Internet
Author: User
Tags redis server

Redis supports 2 persistence strategies: The Snapshot and Commandlog methods, which are implemented by periodically writing the current memory data snapshot to the Rdb file, which is achieved by recording the write operations received by the Redis process in log, and the next time the Redis restarts, Replay the Commandlog to restore the data status.
Depending on the actual requirements, the user can choose to disable persistence completely or enable both RDB and aof in the same Redis instance.
        Special attention:If the deployment mode is the primary, then the persistence of different instances is best staggered! avoid both master and slaves in the background persistence, which may degrade the performance of the system.

1. RDB-related configuration
1) databases
To Configure the number of DB files, you can specify the db file for subsequent persistence with the Select <dbid> directive for each connection, and the new connection uses DB 0 by default
2) Save
The persistence of snapshotting has a variety of save strategies to choose from, and it supports mixing, such as:
Save 900 1
Save 300 100
Save 60 10000
the effect of the above configuration is that snapshotting will be triggered when any one of the 3 conditions is satisfied: a. At least 1 keys in 900s change; b. At least 100 keys in 300s vary; c. 60s has at least 10,000 keys Change
when the save condition is triggered, Redis implements the asynchronous dump disk in the background by a child process by fork. According to the write-time replication policy of fork, if there are many write requests during the persistence process, the memory required is twice times the memory of the current data set in the worst case.
Note 1: The above configuration of the 3 trigger conditions is actually successive enhancement, which condition first satisfied first trigger the save policy.
NOTE 2: If the business does not need to persist or does not require an RDB-style persistence, it can be done by commenting out the Save configuration item
3) Stop-writes-on-bgsave-error
Specifies the behavior of Redis in the background dump disk error, the default is yes, indicating that if the background dump error, then redisserver reject the new write request, in this way to arouse the user's vigilance, to avoid the user did not find the exception caused by a larger accident.
4) Rdbcompression
The RDB file is compressed and, if yes, consumes a bit of CPU while compressing, but saves disk space.
5) Rdbchecksum
If the rdb file requires a CRC64 checksum, if yes, it calculates its CRC64 after the Rdb file is generated and appends the result to the end of the file, as well, when Redis starts the load RDB, it calculates the CRC64 of the file and compares it with the calculated results at dump.
Benefits: The integrity and security of the RDB can be strictly guaranteed
Cost: 10% performance is lost at dump or load. If you want to maximize the performance of Redis, this configuration item should be switched off with no
6) Dbfilename
Specifies the Rdb file name, which defaults to Dump.rdb
7) dir
specifies the path to the directory where the Rdb file is stored, and if a multi-level path is included, the associated parent path must be mkdir beforehand or the startup fails.

2. AOF Related Configuration
By default, Redis persists data in the same way that an RDB file is written (unless the user actively disables the persistence of the RDB mode). If the Redis process hangs or the machine loses power, new data will be lost during the last save completion time until the point of failure.the introduction of AOF can reduce the amount of data loss to 1 seconds or 1 write instructions.
1) appendonly
Configure whether to enable AOF persistence, default to No
2) Appendfilename
Specifies the aof file name, which defaults to appendonly.aof
3) Appendfsync
To configure how aof files are synchronized, Redis supports 3 ways:
A. No and Redis does not actively call Fsync, when the brush disk is dispatched by the OS;
B. Always = Redis actively invokes the Fsync brush disk for each write command;
C. everysec = Fsync Brush disc per second.
Users can choose the appropriate synchronization strategy based on the sensitivity of the business to the data.
4) No-appendfsync-on-rewrite
Specifies whether to call Fsync during background aof file rewrite, which defaults to No, indicating that you want to invoke Fsync (regardless of whether the background has child processes in the brush disk). Note: When Redis writes an RDB file or rewrites a Afo file in the background, there is a lot of disk IO, and in some Linux systems, calling Fsync may block.
5) Auto-aof-rewrite-percentage
Specifies the condition for Redis overriding the AoF file, which defaults to 100, which indicates that AFO background is triggered when the current aof file grows more than 100% of the last rewrite file size compared to the last rewrite aof file size. If configured to 0, automatic rewrite is disabled.
6) Auto-aof-rewrite-min-size
Specifies the size of the aof file that triggers rewrite. If the aof file is less than this value, automatic rewrite is not triggered even if the current file's increment ratio reaches the Auto-aof-rewrite-percentage configuration value. The rewrite is triggered when both configuration items are met at the same time.

3.Need a clear question
1) If you enable both RDB and AFO two persistence modes, when Redis server starts, the aof file is loaded to rebuild the dataset because aof can guarantee that the data is relatively complete.
2) regarding the advantages and disadvantages of the RDB and aof and how the user chooses the appropriate persistence strategy, you can refer toOver here.
3) In short, if you can tolerate data loss, only the RDB is enabled, and if you are sensitive to data, you can enable both RDB and aof;only enable AOF is not recommended(Note the Save configuration entry for the configuration file or the save "" through REDIS-CLI) because the entire dataset cannot be rebuilt once the AoF file is corrupted or if there is a bug in the AOF parsing engine.


This article is from "Linux OPS rookie" blog, please be sure to keep this source http://zhangchuang.blog.51cto.com/10884116/1786955

3. Persistence-related configuration in redis.conf

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.