REDIS02_RDB overview and function, automatic trigger, manual trigger, advantages and disadvantages, trigger scenarios, detailed explanation of configuration items

①. Overview and functions of RDB

  • ①. RDB overview: At a specified time interval, execute a point-in-time snapshot of the data set
  1. The way to achieve a photo-like recording effect is to write the data and status at a certain moment to the disk in the form of a file, which is a
    snapshot. In this way, even if there is a failure, the snapshot file will not be lost, and the reliability of the data is guaranteed.
  2. This snapshot file is called an RDB file (dump.rdb). RDB is the abbreviation of Redis DataBase.
  3. RDB official website
    Insert image description here
  • ②. The role of RBD files
  1. Write the snapshot of the data set in the memory to the disk within the specified time interval, which is the Snapshot memory snapshot in the jargon. When it is restored, the hard disk and the snapshot file are directly read back to the memory.
  2. Redis data is all in memory. When saving a backup, it performs a full snapshot , that is, it records all the data in the memory to the disk.
  3. The file RDB saves to disk is called dump.rdb

②. RDB - automatic trigger

  • ①. The configuration files below Redis6.0.16 are as follows:
    Insert image description hereInsert image description here

  • ②. This case was modified twice in 5 seconds.
    Insert image description here

  • ③. Modify the dump file saving path and dump file name. Customize the
    modified path and you can enter redis and use CONFIG GET dir to obtain the directory.
    Insert image description hereInsert image description hereInsert image description here

  • ④. The first trigger situation:
    Insert image description here

  • ⑤. The second trigger situation:
    Insert image description here

  • ⑥. After the backup is successful, deliberately use flushdb to clear redis to see if the data can be restored.
    Executing the flushall/flushdb command will also generate a dump.rdb file, but it is empty and meaningless.

    Insert image description here

③. Manual trigger - save, bgsave

  • ①. Redis provides two commands to generate RDB files (manually triggered), namely save and bgsave
    Insert image description here

  • ②. Save - Not recommended. Execution
    in the main program will block the current redis server until the persistence work is completed. During the execution of the save command, Redis cannot process other commands, and online use is prohibited.
    Insert image description here
    Insert image description here

  • ③. BGSAVE (default): Redis will perform snapshot operations asynchronously in the background. It does not block snapshots and can also respond to client requests. This trigger method will fork a child process and copy the persistence process by the child process.
    Insert image description here
    Insert image description here

  • ④. You can obtain the time of the last successful snapshot execution through the lastsave command.

# redis侧获得时间戳
127.0.0.1:6369>LASTSAVE 
(integer) 1668604512
# linux
# date -d @1668604512
2022116日 星期三 21:15:12 CST

④. RDB - Advantages reflected

  • ①.Official website description
    Insert image description here

  • ②. Suitable for large-scale data recovery

  • ③. Low requirements for data integrity and consistency

  • ④. RDB files are loaded into memory much faster than AOF.

⑤. RDB - Disadvantages

  • ①. Official website description:
    Insert image description here

  • ②. Make a backup at a certain interval, so if redis accidentally goes down, the data from the current to the latest snapshot will be lost, and the data between snapshots will be lost.

  • ③. Full synchronization of memory data. If the amount of data is too large, I/0 will seriously affect server performance.

  • ④. Data loss cases
    Insert image description hereInsert image description hereInsert image description here

⑥. What situations will trigger RDB snapshots?

  • ①. Default snapshot configuration in configuration file

  • ②. Executing the flushall/flushdb command will also generate the dump.rdb file, but it is empty and meaningless.

  • ③. Manual save/bgsave command

  • ④. Execute shutdown without setting to enable AOF persistence.

  • ⑤. During master-slave replication, the master node automatically triggers

⑦. Detailed explanation of RDB optimization configuration items

  • ①. Method to dynamically stop all RDB saving rules: redis-cli config set save "", the configuration file is as follows:
    Insert image description here

  • ②. Commonly used RDB configurations are as follows:

  1. save <seconds> <changes>
  2. dbfilename: file name
  3. dir: file directory
  • ③. stop-writes-on-bgsave-error: The default is yes.
    If configured to no, it means that you do not care about data inconsistency or have other means to discover and control such inconsistencies. This will ensure that redis continues to accept new data when the snapshot writing fails. write request
    Insert image description here

  • ④. rdbcompression: The default is yes.
    For snapshots stored on disk, you can set whether to compress and store them. If so, redis will use the LZF algorithm for compression. If you don't want to consume CPU for compression, you can set it to turn off this function.
    Insert image description here

  • ⑤. rdbchecksum: The default is yes.
    After storing the snapshot, you can also let redis use the CRC64 algorithm for data verification, but doing so will increase performance consumption by about 10%. If you want to get the maximum performance improvement, you can turn off this function.
    Insert image description here

  • ⑥. rdb-del-sync-files: Enable deleting RDB files used in replication without persistence. By default no, this option is disabled
    Insert image description here

Guess you like

Origin blog.csdn.net/TZ845195485/article/details/130300391