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

Usage and Application scenario of RDB data persistence in redis

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

Share

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

Unlike Memcache, Redis persists data to the hard disk. Redis currently provides three persistence methods: mixed persistence of RDB, AOF and RDB-AOF. Data security and backup are the key points in operation and maintenance work. Let's take a look at the introduction and application scenario of RDB persistence.

The default persistence method used by Redis is that RDB,RDB files take up very little space, so the file is generated and loaded quickly.

Generate RDB file

Generating RDB files can be divided into manual and automatic methods.

First of all, look at the manual way, there are two commands can trigger the generation of RDB files. Save and bgsave, the difference is that the save operation blocks the redis until the RDB file is generated. Bgsave, on the other hand, does not block redis, it will fork a child process and complete the generation of the rdb file in the child process.

There are several situations of automatic mode, which are as follows:

The modification operation of the current key meets the configuration requirements of Rdb in redis

When the master-slave node makes a full copy

When restarting or shutting down redis (Redis persistence mode is RDB)

Here, let's focus on the relevant configuration of rdb.

The directory saved by the rdb file is determined by the dir configuration item

# rdb file save directory dir "/ usr/local/redis/var"

The file name is determined by dbfilename

Dbfilename "dump.rdb"

The trigger mechanism has a save decision.

Save 900 1save 300 10save 60 10000

The meaning of the above configuration is that it is triggered when there is one modification in 900 seconds, 10 modifications in 300 seconds, and 10000 modifications in 60 seconds.

In addition, the rdbcompression configuration item determines whether to compress the rdb file. The default is yes, which means compression, which is also the recommended way.

RDB file generation process

Because save is almost obsolete, redis automatic trigger uses bgsave operation, so only the process of bgsave is introduced here.

When bgsave is executed, if there is already a child process, redis exits directly and does not perform the following actions. If not, proceed.

The redis main process will fork a child process. Redis is blocked at fork, but for a very short time.

After the success of the fork, the Redis main process continues to do what it has to do.

The child processes generate a new RDB file and replace the old rdb file.

When the replacement operation is complete, the child process notifies the parent process, and the parent process saves the information about the operation.

Application scenario

RDB files are small in size and fast to generate and load, but rdb persistence can not achieve real-time persistence, which can easily lead to data loss in abnormal cases. In addition, there may be incompatibility between different versions of rdb files.

From the above introduction, you can know that RDB files are very suitable for disaster recovery backup, such as generating RDB files in the early hours of every day. In addition, if the data stored in redis is not too important, such as using redis for caching, it is usually better to use RDB if it does not affect the loss of some data.

Then introduce the solution to a common problem, how to write data to another partition without stopping redis when the partition of redis data is almost full. We can use config set dir 'new partition directory' to modify the directory where the rdb file is stored. Then execute bgsave to generate a new RDB file to the new directory.

These are the details of RDB for redis data persistence, please pay attention to other related articles!

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