RDB notes for Redis persistence

1. What is RDB

  • Write a snapshot of the data set in memory to disk within a specified time interval,
  • It is also called Snapshot in the jargon. When it is restored, it reads the snapshot file directly into the memory.
  • Redis will create (fork) a child process for persistence. It will first write the data to
    a temporary file. After the persistence process is over, it will replace the last persisted file with this temporary file. During the entire process, the main process does not perform any IO operations, which ensures extremely high performance.
    If large-scale data recovery is required, and the integrity of data recovery is not very sensitive, the RDB method is better than the AOF method Efficient. The disadvantage of RDB is that the data after the last persistence may be lost.

2、Fork

  • The role of Fork is to copy a process that is the same as the current process. All data (variables, environment variables, program counters, etc.) of the new process have the same values ​​as the original process, but it is a brand-new process and is a child process of the original process

3. Rdb saves the dump.rdb file

Specifically, you can configure the default dump.rdb in redis.conf

Insert picture description here

4. How to trigger RDB snapshot

1) Trigger snapshot The
Insert picture description here
default trigger snapshot condition configuration is:

  • Change 10,000 times in 60 seconds
  • Change 10 times in 300 seconds
  • Change once in 900 seconds

2) Take a snapshot by using the command

  • Save: Just save when saving, no matter what else, all blocked
  • BGSAVE: Redis will perform snapshot operations asynchronously in the background, and snapshots can also respond to client requests. The time of the last successful execution of the snapshot can be obtained through the lastsave command

3) Note that using flashall command will also generate a snapshot, but an empty snapshot is meaningless

5. How to recover data

  • Move the backup file (dump.rdb) to the redis installation directory and start the service
  • CONFIG GET dir Get the directory, view the location where the snapshot is generated, that is, the location configured in the redis.conf configuration file

Insert picture description here

  • When the dump.rgb file fails, redis-check-rdb --fix the rgb file to be checked, and reply to the file.

6. Advantages of RDB

  • Suitable for large-scale data recovery
  • Low requirements for data integrity and consistency

7. The disadvantages of RDB

  • Make a backup at a certain interval, so if redis is accidentally down, all the changes after the last snapshot will be lost
  • When Fork, the data in the memory is cloned, and roughly 2 times the expansion needs to be considered

8. How to stop using RDB

  • All methods of stopping RDB saving rules dynamically: redis-cli config set save ""
  • The configuration file will be changed to the content in the red box

Insert picture description here

Guess you like

Origin blog.csdn.net/magicproblem/article/details/113113046