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

Persistence of redis

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Why should it be persistent? Without considering the server downtime, it is not necessary to save the data in memory to disk for persistence.

Persistence is a remedy specially prepared for downtime. Redis has two persistence mechanisms: rdb and aof.

1. RDB (Redis DataBases)

Principle:

The current process fork gives a child process, which iterates through all the data and saves the data to the RDB file.

Timing:

Persist the data according to the policy set by the configuration file.

Configuration:

Save 900 1

Save 300 10

Save 60 10000

2. AOF (AppendOnly File)

Principle:

Redis will append every write command received from the client to the end of the aof file.

Timing:

Each time a command is written, the action is recorded.

Configuration:

Appendonly yes

# No modification is required by default. The minimum 64m starts to be rearranged, and the rearrangement ratio is double that of the last time, 128m, 256m, 512m.

Auto-aof-rewrite-percentage 100

Auto-aof-rewrite-min-size 64mb

Third, the comparison persistence of RDB and AOF:

RDB waits for write conditions with low frequency. If more data is written at one time, it may bring stutter to the server.

AOF immediately records each write command with high frequency and very little data each time; the resulting file will be larger than that generated by RDB.

AOF records data in a more timely manner and is less likely to lose data.

Data recovery:

When RDB recovers data, it reads the data directly from the RDB file, which is very fast.

When AOF recovers data, it needs a command to operate the redis server, which is inefficient.

4. Why do AOF instructions rearrange aof instructions need to be rearranged:

Set aa 1

Set aa 2

Set aa 3

Three instructions, in fact, only need to save the last one, the meaning of instruction rearrangement is to turn three into a set aa 3.

The current process fork a child process, and the child process completes the instruction rearrangement.

It is important to note that during the instruction rearrangement of the child process, if a new instruction appears, the main process does two things:

1. Append the instruction to the end of the old aof file

two。 Save the instruction to the cache. All the data in the cache is appended to the end of the new aof file after the child process completes the instruction rearrangement.

Fifth, how to choose the way of persistence after the above analysis, we already know the advantages and disadvantages of rdb and aof. You can choose the appropriate way according to the specific business scenario.

Of course, it is possible to use both methods at the same time.

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