Redis Persistence Append only file

Source: Internet
Author: User
Tags redis server

1, or first look at the official documents:


650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/95/60/wKiom1kUYB7T0ioxAACFTjabcQQ002.png "title=" 01. PNG "alt=" Wkiom1kuyb7t0ioxaacftjabcqq002.png "/>

Note: AOF persistent day aspiration server gets each occurrence of the write operation, which executes at the time of server startup to restore the original data set. These write commands are journaled in the same format as the Redis protocol itself. When this log file is too large, redis can rewrite the log in the background. (The read operation is not logged, the operation simply appends the file contents and does not allow overwriting of the file.) )

If you want, you can be completely non-persistent, and this usually happens when the server is running with data on the line.

AOF and RDB can be used together in the same instance. In this case, the AOF file is re-executed when the Redi is turned on so that the original data set is restored (because this recovery is the most complete).


2, specific to see how to operate:


A, set the redis.conf file, in order to make the configuration file is not too complex, use the CP command to back up a redis_aof.conf file.


650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/95/61/wKiom1kUZtyxkuwzAABIABOoyxY274.png "title=" 02. PNG "alt=" Wkiom1kuztyxkuwzaabiabooyxy274.png "/>

Note: The default is AppendOnly no, as described in the previous configuration file, modify AppendOnly Yes to open AOF.

b, in the write operation, Redis creates a appendonly.aof (that is, the Redis persistence log file) in the working directory.

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/95/61/wKioL1kUaLOw0NQYAAA-Ip3sG5k642.png "title=" 04. PNG "alt=" Wkiol1kualow0nqyaaa-ip3sg5k642.png "/>

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/95/61/wKiom1kUaNaB8UU2AAAfCjlI-PM721.png "title=" 05. PNG "alt=" Wkiom1kuanab8uu2aaafcjli-pm721.png "/>


C, after executing the flushall command, close the server, use the ls-l command to view the file, and then use the Cat command to view the appendonly.aof file. (You can see that AOF and RDB can be used together in the same instance.) )


650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/95/61/wKioL1kUbV6T2tbjAAAdXuplFas917.png "title=" 13. PNG "alt=" Wkiol1kubv6t2tbjaaadxuplfas917.png "/>

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/95/61/wKiom1kUaW3C95cNAAAacl5c03U826.png "title=" 06. PNG "alt=" Wkiom1kuaw3c95cnaaaacl5c03u826.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/95/61/wKiom1kUaa_R962kAAA6cfP6RuM342.png "title=" 07. PNG "alt=" Wkiom1kuaa_r962kaaa6cfp6rum342.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/95/61/wKioL1kUadmQumqoAAAZtVVlXQs647.png "title=" 08. PNG "alt=" Wkiol1kuadmqumqoaaaztvvlxqs647.png "/>


Note: As shown, you can see that appendonly.aof records all the write commands, including select 0,flushall, if you restart the server, query with keys, or empty results are displayed.


650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/95/61/wKioL1kUaoHz166eAAAkxIW8fEM389.png "title=" 09. PNG "alt=" Wkiol1kuaohz166eaaakxiw8fem389.png "/>


D, after the last flushall in the appendonly.aof file is deleted, start the server.


650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/95/61/wKioL1kUaz_Q4RM4AAApAa-Qmks563.png "title=" 10. PNG "alt=" Wkiol1kuaz_q4rm4aaapaa-qmks563.png "/>


Note: You can see that the data has been restored


E, after shutting down the server, destroy the Appendonly.aof file, and then start the server.


650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/95/61/wKiom1kUbIOyntoqAAAcKMgDXFE212.png "title=" 11. PNG "alt=" Wkiom1kubioyntoqaaackmgdxfe212.png "/>

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/95/61/wKiom1kUbMrBZ25DAAAtgIRzqoQ287.png "title=" 12. PNG "alt=" Wkiom1kubmrbz25daaatgirzqoq287.png "/>


The server was unable to start after a corrupted file was found. It can be concluded that in the same instance, AOF and RDB are used together, and Redis takes precedence from the appendonly.aof file to memory when the server is turned on, and then executes the command.


F, after you type the/usr/local/bin/redis-check-aof--fix appendonly.aof instruction, you can restart the Redis server.


650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/95/62/wKioL1kUcYfB39KXAABgevkaPCs524.png "title=" 14. PNG "alt=" Wkiol1kucyfb39kxaabgevkapcs524.png "/>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/95/62/wKioL1kUccfQHYeiAAAp9omYomw775.png "title=" 15. PNG "alt=" Wkiol1kuccfqhyeiaaap9omyomw775.png "/>


3, redis.conf on the AOF of other related configuration:


A, appendfsync configuration operation:


650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/95/62/wKioL1kUc0yCm54cAADQT08tATU245.png "title=" 16. PNG "alt=" Wkiol1kuc0ycm54caadqt08tatu245.png "/>


You can see the following:

Always: synchronous persistence, which logs operations to disk as soon as data changes occur, which is safe, but poorly performing.

Everysec: Factory default setting, asynchronous operation, record per second. If you swing the machine within one second, the data in this second will be lost.

No: The data change operation is not recorded on the disk.


B, No-appendfsync-on-rewrite: If this parameter is set to No, it is the safest way to not lose data, but to endure the problem of blocking. If set to Yes, this is equivalent to setting the Appendfsync to No, which means that no disk operation is performed, only the buffer is written


650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/95/63/wKiom1kUdYbDC9xIAAAyGAEovKE720.png "title=" 17. PNG "alt=" Wkiom1kudybdc9xiaaaygaeovke720.png "/>


5, AOF's rewrite:


A, AOF the use of file Append method, which means that the document will be more and more large. In response to this problem, a new rewrite mechanism is added, and when the size of the AOF file exceeds the threshold threshold (critical value), Redis initiates the content compression of the AOF file, saving only the smallest set of instructions for the data.


B, overriding principle:

AOF file continues to grow too large, it will fork out a new process to rewrite the file (also write the temporary file and finally rename). Iterates through the in-memory data of the new process, with a set statement for each record.

Overriding the AoF file operation, and not reading the old aof file, but instead overwrites the entire in-memory database content with a command to rewrite a new aof file, which is similar to a snapshot.


C. When Redis records the AOF size of the last rewrite, the default configuration is triggered when the AOF file size is one times the size of the last rewrite and the file is larger than 64M.


6, AOF relative to the RDB disadvantage:


A, the data of the same data set, the AoF file is much larger than the Rdb file, the recovery speed is slower than the RDB.


b, aof operation efficiency is slower than RDB, the strategy of synchronization per second efficiency is better, the synchronization efficiency and the same RDB.

This article is from the "12392717" blog, please be sure to keep this source http://12402717.blog.51cto.com/12392717/1924767

Redis Persistence Append only file

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.