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

Redis persistence

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Redis persistence

Overview of ■ persistence

● Redis is running in memory, and the data in memory is lost after power outage.

● in order to be able to reuse Redis data, or to prevent system failure, we need to Redis

The data in is written to disk space, that is, persistence

■ persistence classification

Highlight

● RDB: get copies of all the data in the Redis at a certain time by creating a snapshot

● AOF mode: write the executed write command to the end of the file and write it down as a log

Record changes in data

RDB: takes up less resources and does not need to spend a lot of server resources

AOF: set up a special process to save data at any time, read and write synchronously, similar to incremental backup, but take up more resources. When you restart the service, you need to synchronize data, resulting in slow startup time and long waiting time. The server shuts down suddenly and is not afraid of data loss. Do not execute the last statement

RDB persistence 2-1

Default persistence mode of ■ Redis

■ default file name dump.rdb

■ trigger condition

● performs a specified number of writes within a specified time interval (profile control)

● executes save or bgsave (asynchronous) commands

● executes the flushall command to empty all data in the database

● executes the shutdown command to ensure that the server shuts down normally and does not lose any data

Default persistence mode of ■ Redis

■ default file name dump.rdb

■ trigger condition

To perform a specified number of writes within a specified time interval (profile control)

● executes save or bgsave (asynchronous) commands

Execute the flushall command to empty all data in the database

● executes the shutdown command to ensure that the server shuts down normally and does not lose any data

The safest way to save data in shutdown save

● is suitable for large-scale data recovery.

● if the business does not require high data integrity and consistency, RDB is a good choice

The integrity and consistency of ● data is not high

● backup takes up memory

RDB startup method:

Save instructs to perform a photo manually

● dbfilename dump.rdb

Description: sets the file name of the local database. The default is dump.rdb.

Experience: usually set to dump- port number .rdb

● dir

Description: sets the path where .rdb files are stored

Lesson: usually set to a directory with a large storage space, the directory name data

● rdbcompressionyes

Description: sets whether to compress data when storing to the local database. Default is yes, and LZF compression is used.

Lesson: it is usually on by default. If set to no, you can save CPU running time, but make the stored files larger (huge)

● rdbchecksum yes

Description: set whether to check the RDB file format, which is carried out during both writing and reading of the file.

Experience: it is usually on by default. If it is set to no, it can save about 10% of the time consumed in the reading and writing process, but there is a certain risk of data corruption in storage.

Save is saved sequentially, so it is easy to block the server.

Bgsave manually starts the background save operation, but does not execute it immediately

Note: the bgsave command is optimized for the save blocking problem. All RDB operations within Redis are bgsave, and the save command can be discarded.

Save second changes

Function: to meet the change of key within a limited time range to achieve the specified number of persistence

Parameter second: monitoring time range changes: monitoring the change of key

Full ● replication

Explain in detail in master-slave replication

Restart the ● server during operation

Debug reload

● specifies to save data when shutting down the server

Shutdowm save

AOF data persistence

■ Redis is not enabled by default

■ makes up for the deficiency of RDB (data inconsistency)

■ records each write in the form of a log and appends it to the file

■ Redis restart will execute write instructions from front to back according to the contents of the log file

Line once to complete the data recovery work

Rewriting Mechanism of ■ AOF

● AOF works by appending writes to a file, and the more redundant the file will be.

The more you come

● when the size of the AOF file exceeds the set threshold, Redis will treat the AOF file

Content compression of

Principle of ■ AOF rewriting

● Redis will fork a new process and read the data in memory (not the old one)

File), and rewrite to-a temporary file, and finally replace the old aof file

AOF rewriting

As commands continue to be written to AOF, the file becomes larger and larger. To solve this problem, Redis introduces an AOF rewriting mechanism to compress the file volume. AOF file duplicates

Writing is the process of converting data within a Redis process into write commands and synchronizing it to a new AOF file. To put it simply, several commands for the same data will be executed.

The result is converted into the instruction corresponding to the final result data to be recorded.

AOF rewriting effect

● reduces disk usage and increases disk utilization

● improves persistence efficiency, reduces persistence write time, and improves IO performance.

● reduces data recovery time and improves data recovery efficiency.

Rewrite configuration of ■ AOF

Vim / etc/redis/6379.conf

# when BGREWRITEAOF the log, if it is set to yes, it means that the new write operation does not synchronize fsync, but only

Temporarily stored in the buffer to avoid disk I0 operation conflicts, and write after the rewrite is completed. No is the default in redis

No-appendfsync-on-rewrite no

# BGREWRITEAOF occurs when the current AOF file size is twice the size of the AOF file in the last log rewrite

Auto-aof-rewrite-percentage 100

# the minimum value for the current AOF file to execute the BGREWRITEAOF command to avoid starting Reids due to the file ruler

Smaller inches lead to frequent BGREWRITEAOF

Auto-aof-rewrite-min-size 64mb

# appendfsync always synchronizes AOF with each write operation

Appendtsync everysec data of 1 second per second in case of system downtime

# appendfsync no system Control

Aof-load-truncated yes

# when BGREWRITEAOF the log, if it is set to yes, it means that the new write operation does not synchronize fsync, but only

Temporarily stored in the buffer to avoid disk I0 operation conflicts, and write after the rewrite is completed. No is the default in redis

No-appendfsync-on-rewrite no defaults to no

# BGREWRITEAOF occurs when the current AOF file size is twice the size of the AOF file in the last log rewrite

Auto-aof-rewrite-percentage 100

# the minimum value for the current AOF file to execute the BGREWRITEAOF command to avoid starting Reids due to the file ruler

Smaller inches lead to frequent BGREWRITEAOF

Auto-aof-rewrite-min-size 64mb

AOF rewriting mode

● manual rewrite

Bgrewriteaof

● automatic rewrite

Auto-aof- rewrite-min-size size

Auto-aof-rewrite-percentage percentage

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

Servers

Wechat

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

12
Report