1. For Redis persistence, check the official documentation:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/95/4D/wKiom1kT6hvhBtUdAACZ_3XtiFg032.png "title=" 01. PNG "alt=" Wkiom1kt6hvhbtudaacz_3xtifg032.png "/>
Note: Redis offers a number of different ways to persist options:
An RDB (that is, Redis database) persists a snapshot of a point in time over a specific time interval. It can be understood that a snapshot of an in-memory dataset is written to disk at a specified time interval, which is often said to be a snapshot snapshot, which, when restored, is read directly into memory by the snapshot file.
AOF records all write commands on the server durably, and executes them when the server restarts. (about AOF will be introduced in the next Article blog post.) )
Supplemental Instructions: (Redis setting operation command to connect database password)
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/95/4E/wKiom1kT6-XxBSGZAACBhkoXLvM153.png "title=" 02. PNG "alt=" Wkiom1kt6-xxbsgzaacbhkoxlvm153.png "/>
Note: Use config set requirepass "password" can set or modify the connection password, you can see, set the connection password, immediately take effect, the next time you operate the database, you need to enter the connection password (auth connection password)
2, the RDB detailed description:
Redis first creates a subroutine (fork) to persist, writes the data to a temporary file, and replaces the last persisted file with this temporary file after the persistence process is finished. The main process is not performing any IO operations throughout the process, which ensures very high performance.
If large-scale data recovery is required and the full line of data recovery is not optimistic, the RDB approach requires large-scale data recovery and is not very sensitive to the integrity of the data recovery, which is more efficient than the AOF approach. The disadvantage of the RDB is that the last persisted data may be lost.
The role of fork: Copy a process that is the same as the current process. All the data for the new process (variables, environment variables, program counters, etc.) are consistent with the original process, but are a completely new process and as a child of the original process.
Concept said so much, to see the operation: (note to open two terminals operate separately)
A, in the redis.conf configuration information in the blog post has already mentioned the question of Save, here in addition to explain. Snapshotting is a snapshot, you can see that when set to save "", it is not taken. (Annotated in the illustration) if set to save 120 10, it means that in 120 seconds, if 10 keys are deleted, modified, or added, Redis will automatically save the DB to disk.
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/95/4E/wKioL1kT8MbzMvUjAADkuzUiPZY655.png "title=" 03. PNG "alt=" Wkiol1kt8mbzmvujaadkuzuipzy655.png "/>
b, you can see, in 2 minutes, I saved 14 key,redis after 2 minutes, automatically generate a Dump.rdb file in the specified directory.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/95/4E/wKiom1kT8i2ydC0LAAChulOu5VU782.png "title=" 04. PNG "alt=" Wkiom1kt8i2ydc0laachulou5vu782.png "/>
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/95/4E/wKiom1kT8meRpAznAAAdeiZmbv8734.png "title=" 05. PNG "alt=" Wkiom1kt8merpaznaaadeizmbv8734.png "/>
Note: (A mistake made by yourself) because Redis is configured under path path, it is no problem to start Redis in that directory. The default file name for DB is Dump.rdb, which will be saved in the directory where you started the Redis backend server. If it is started after the input Su-command, it is directly under the/root directory.
C, a backup of the data here, the Dump.rdb backup, renamed to Dump_db.rdb
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/95/4E/wKioL1kT9FPxgjFxAAAx3U_eDxQ686.png "title=" 06. PNG "alt=" Wkiol1kt9fpxgjfxaaax3u_edxq686.png "/>
D, then clear the operation in Redis, and then close the service
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/95/4E/wKioL1kT95nSL_fPAAAv3OnCojw597.png "title=" 07. PNG "alt=" Wkiol1kt95nsl_fpaaav3oncojw597.png "/>
Note: In the operation, it was found that the creation time of Dump.rdb changed after Fluahsall, that is, Redis overwrites the source file with an empty Dump.rdb file.
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/95/4E/wKioL1kT-C2xFr3GAAApuw65Kpk359.png "title=" 08. PNG "alt=" Wkiol1kt-c2xfr3gaaapuw65kpk359.png "/>
E, restart Redis, use keys * to find that the original data does not exist. (It is also understandable that after Flushall, the Dump.rdb file has been overwritten, and Redis reads from disk into memory an empty document).
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/95/4E/wKioL1kT-P-jNUEnAAAfc433JeU683.png "title=" 09. PNG "alt=" Wkiol1kt-p-jnuenaaafc433jeu683.png "/>
F, turn off Redis again, use the CP command to copy the Dump_db.rdb overlay Dump.rdb file, start Redis again, and discover that the data already exists.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/95/4F/wKiom1kT-YmwOx8iAAAs0D3EQ7M945.png "title=" 10. PNG "alt=" Wkiom1kt-ymwox8iaaas0d3eq7m945.png "/>
Note: Only 10 pieces of data are retrieved, consistent with the save configuration in the configuration file, that is, using an RDB in the event of an exception may cause the data to be partially lost when it is last saved to disk.
Attached: The Dump.rdb file will also be overwritten when the save operation is performed.
The difference between the bgsave operation and the save operation is that:
Save while saving, others, all blocked.
Basave,redis, in the background, asynchronously makes snapshot operations, and the snapshot can also respond to client requests. You can also use the Lastsave command to get the last successful snapshot execution time.
3. Supplemental information about the RDB on the redis.conf configuration file:
A, Stop-writes-on-bgsave-error: Stop the write operation when the SAVEBG operation fails. If configured as no, you do not care about data consistency or other ways to solve the problem.
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/95/4F/wKiom1kT-3GzXTO2AAAiYppK5dE613.png "title=" 11. PNG "alt=" Wkiom1kt-3gzxto2aaaiyppk5de613.png "/>
B, rdbcompression: For snapshots stored on disk, whether to compress save. If so, use the LZF algorithm to compress the save. If you do not want to consume the CPU to do this, you can turn off the feature.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/95/50/wKiom1kT_aCSJjWbAAAkS7Uk8yA290.png "title=" 12. PNG "alt=" Wkiom1kt_acsjjwbaaaks7uk8ya290.png "/>
C, Rdbchecksum: After storing the snapshot, you can also have Redis use the CRC64 algorithm for data validation, but doing so will increase the performance consumption by approximately 10%, and you can turn off this feature if you want to get maximum performance gains.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/95/50/wKiom1kT_mXh46q4AAAz8KJgDCY098.png "title=" 13. PNG "alt=" Wkiom1kt_mxh46q4aaaz8kjgdcy098.png "/>
4, RDB Performance Summary:
Advantages: 1, suitable for large-scale data recovery
2, the data integrity and consistency requirements are not high
Disadvantage: 1, at a certain time interval to do data backup, if Redis accidentally swing machine, you will lose all the changes after the last snapshot.
2, fork, the memory of the data is cloned again, roughly twice times the expansion of the need to consider.
This article is from the "12392717" blog, please be sure to keep this source http://12402717.blog.51cto.com/12392717/1924462
Redis Persistence Redis Database