I. Overview
The power of Redis is largely due to the fact that the data is in memory, but when the Redis restarts, all the data stored in memory is lost, so we persist the data in memory.
Redis supports two ways to persist data: RDB mode and AOF mode.
(1) The Rdb method persists the in-memory data to the hard disk on a timed basis according to the configured rules.
(2) AOF the command after each execution of the write command.
1.RDB mode
The persistence of the RDB mode is done by means of a snapshot. When a rule is met, all in-memory data is generated in a single copy stored on the hard disk, and Redis snapshots the data in the following situations:
A: Automatic snapshots based on the configured rules.
B: The user executes the save, Bgsave command.
C: Execute the flushall command.
D: Perform replication (replication).
(1) Automatic snapshot according to configuration
Redis allows users to customize snapshot conditions and automatically perform snapshots when conditions are met, and the snapshot rules are configured as follows:
(2) Execute save, Bgsave command
We can manually perform the save, Bgsave command to take the snapshot operation proactively.
Save: When you execute the Save command, Redis synchronizes the snapshot operation, which blocks all requests from the client, so you should avoid using the command when you put more database data.
Bgsave: As can be seen from the command name, this command differs from the Save command in that the snapshot operation of the command is performed asynchronously in the background, while the snapshot operation can also handle requests from the client. After executing the bgsave command, Redis returns OK immediately to start the snapshot operation, and if you want to know if the snapshot operation is complete, you can use the Lasesave command to return the last time the snapshot was successfully executed, and the result is a UNIX timestamp.
Redis Basic Learning (iv) Persistence of-redis