Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

RDB snapshot of Redis persistence

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

What is RDB?

1. Redis data is stored in memory, and a binary file of rdb can be created on hard disk by save or bgsave. This rdb file is equivalent to a snapshot of redis data.

2. After Redis restarts, it loads the contents of the rdb file on the hard disk into memory.

RDB can also be used as a medium for copying file transfers. For example, redis master-slave replication is transmitted through rdb.

Three ways to trigger RDB

1. The save command

1. The save command creates snapshots synchronously.

The Redis client sends the save command, and the redis server packs all the data in memory, creates an rdb file on the hard disk, and saves the data.

Save Sync blocks other client requests.

Because redis is single-threaded, save blocks requests from other redis clients while creating an rdb file. When rdb creation is complete, blocking ends.

Second, bgsave command

1.bgsave Create Snapshots Asynchronous

The client sends the bgsave command, and redis server forks a child process that packs the data in redis server memory into an rdb file on hard disk.

2. bgsave asynchronous non-blocking

Redis server will block other client requests for a short time (short time, can be ignored) in the process of fork child process, and the child process will not block other client requests after creation. The child process creates the rdb file asynchronously after the child process is successfully created, and sends a signal to the main process after the save is complete, notifying that the save is complete. The fork child process is fast, and the fork child process consumes extra memory.

As shown, the process name is redis-rdb-bgsave

III. Automatic trigger

Configuration for snapshot creation in redis.conf

save 900 1save 300 10save 60 10000

IV. Document generation strategy

Generate temporary files first, and replace the dump.rdb file with temporary file area when snapshot creation is complete.

V. Other trigger mechanisms

1. When master/slave needs to perform full replication, master service will perform bgsave operation.

2. debug reload debug restart

3. When shutdown is executed

Features of RDB:

Advantages:

1. It is suitable for large-scale data recovery and has low requirements for data integrity and consistency.

Disadvantages:

1. Redis creates rdb snapshots at intervals, and if it goes down after the last snapshot is created, the modified data after the last snapshot will be lost.

2. bgsave operation (including automatic trigger to create rdb) creates rdb snapshot in fork child process, copies data in memory, consumes a certain amount of memory.

Dynamic shutdown Automatic snapshot creation

127.0.0.1:6379>config save ""

View rdb file location

127.0.0.1:6379> CONFIG GET dir1) "dir"2) "/var/lib/redis"

Rdb related configuration in redis.conf

#Specify rdb file name

dbfilename dump-${port}.rdb

#Specify the data storage directory (working directory)

dir ./

#bgsave Stop writing data when an error occurs

stop-writes-on-bgsave-error yes

#Recording data in compressed form

rdbcompression yes

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report