8. Basic Redis commands-management-persistence-RDB, redis-rdb

Source: Internet
Author: User

8. Basic Redis commands-management-persistence-RDB, redis-rdb
1. Redis supports two methods of Persistence: RDB and AOF. It can be used separately or in combination.
2. The rdb a and RDB modes are the default persistence methods adopted by Redis, which are completed through snapshots. When certain conditions are met, Redis automatically takes snapshots of all data in the memory and stores them on the entire hard disk. Snapshot conditions: time and number of modified keys. When the number of keys changed within the specified time is greater than the specified value, a snapshot is taken. B. Three conditions have been set in the configuration file: save 900 1 save 300 10.
Save 60 10000
C. The save parameter specifies the snapshot conditions. Multiple conditions can be saved. The conditions are in the "or" relationship. As shown above, a snapshot is taken when at least one key is changed within 900 seconds. The unit of time is second.
D. Redis stores the snapshot file in the dump. rdb file of the current directory by default. You can also specify the storage path and file name of the snapshot file by using the dir and dbfilename parameters.
E. Redis snapshot process: 1) Redis uses the fork function to copy a copy of the current process (parent process) (child process) 2) the parent process continues to accept and process commands sent from the client, and the child process starts to write data in the memory to temporary files in the hard disk.
3) after the sub-process writes all the data, it replaces the old RDB file with the temporary file, and this snapshot operation is completed.
F. When fork is executed, the operating system uses the copy-on-write policy. That is, when the fork () function occurs, the Parent and Child processes share the same memory space, when a parent process needs to change a piece of data (such as executing a write command), the operating system will copy the data to ensure that the data of the child process is not affected, therefore, the new RDB file stores the memory data at the moment of fork.
G. Redis replaces the old RDB file with the new one after the snapshot is complete, that is, the RDB file is complete at any time. In this case, we can back up Redis data by backing up the RDB file. H. RDB files are compressed in binary format, so the occupied space is smaller than the data size in the memory, which is more conducive to transmission. You can also set the redcompression parameter to disable compression.
I. manually execute the snapshot command in Redis: SAVE \ BGSAVE. The difference is that the former is a snapshot operation performed by the main process and other requests are blocked, the latter takes snapshots through the fork sub-process. J. After Redis is started, it reads the RDB snapshot file and loads the data from the hard disk to the memory.
K. Data Persistence in RDB mode. Once Redis exits abnormally, the data changed after the last snapshot is lost. If the data is so important that it cannot bear any losses, you can use AOF for persistence.









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.