One. Overview
The persistence feature of Redis is the decision that Redis can be the core of a certain functional database.
There are a total of two ways to persist in Redis, an RDB, and a aof approach.
Note: We do not need to use the persistence of Redis, without using the persistence feature,
Decide that we are using Redis as a cache, which is no different from memcache.
Two. The fundamentals of an RDB
Redis is a single process, and when we turn on RDB data persistence, Redis will fork a new process to help implement the functions of the RDB.
In fact, the function of the RDB is very simple, is to periodically snapshot the Redis memory. When the snapshot is complete, replace the original snapshot content.
This is done when Redis uses the next boot directly to read the snapshot files directly into Redis.
The related configuration of the snapshot is concentrated in the redis.conf file.
Three. View Redis.conf file
We found the snapshot portion of the Redis configuration file.
For example, this section is the configuration for the snapshot portion of Redis.
Note: The default for Redis is to use snapshots for persistence.
Save Policy:
The text above represents the save policy for Redis in RDB mode.
Explain the above text:
[1]save 900 1--a snapshot is taken once in 900 seconds.
[2]save---300 seconds 10 This write operation will take a snapshot once.
[3]save 60 10000:10000 for 60 seconds, a snapshot is taken.
The above snapshot policy we can fix, adjust to a better way.
When we do not set any save policy, the RDB does not take a snapshot.
When we appear RBD persistent error. Whether the write operation is forbidden.
This ensures the consistency of the Redis data, but when errors occur, it can affect the use of redis.
RDB Persistence is compressed: The RDB is compressed by default.
If you want to perform the highest performance, turn off the compression function directly, but the pressure on the storage will become larger.
Whether to turn on the RDB checksum.
If you want to get the highest performance, you can set it to No. Of course the correct data may be problematic.
The location where the Rdb file is saved and the name of the file saved.
When we query the redis.conf file, we can see that there is a Dump.rdb file underneath the file. This is the snapshot file for the RDB.
Four. The advantages and disadvantages of an RDB
Advantage: The RDB has a higher performance because the RDB holds the final result set.
Disadvantage: The RDB is not real-time and can result in loss of data.
The last data saved will be discarded when the data is lost.
Summary: If the integrity of the data requirements are not high, we can use the RDB approach, such performance will be higher.
Advanced:
[1] An RDB requires more memory overhead because it needs to turn on a fork process to monitor the RDB.
[2] When the amount of data is very large, the RDB performance is poor, because the snapshot of the IO operation at a high cost.
010 Redis Persistent RDB