当前位置:网站首页>Redis - persistent RDB and persistent AOF
Redis - persistent RDB and persistent AOF
2022-06-30 18:25:00 【Salted fish_ Turn over】
List of articles
brief introduction
because Redis It's a memory based database , If you do not save the database state in memory to disk , So once the data server process exits , The database state in the server will disappear , therefore Redis Provides persistence , Persisting data from memory to a file .
There are two ways to persist :
RDB
AOF
These two persistence methods will be introduced below
RDM
1. What is? RDM
RDB, Full name Redis DataBase, Writes a dataset snapshot to disk within a specified time interval , Read these snapshot files into memory when recovering data , In the corresponding configuration file SNAPSHOTTING.
Redis A child process will be created separately fork,fork Is to copy a process exactly like the current process as a child process of the original process for persistence ,fork The data is written to a temporary file , After the persistence operation is completed , The temporary file will replace the file that has been persisted , In the process , The main process does not perform any IO operation , This ensures that RDB Extremely high performance , Compared with RDB and AOF,RDB The mode of AOF More efficient . If you are recovering big data , And the accuracy of the data is not high , Then you can use it RDB,Redis The persistence of the default is also RDB, In general ( Production environment ) There is no need to modify this configuration .
By default , Redis Save the database snapshot in a file named dump.rdb In the binary file of . The file name can be customized in the configuration file , Sometimes in the production environment, we Backup this file !
2.RDB The trigger mechanism of
1、 Meet the requirements of the configuration file save In the case of rules , Will automatically trigger RDB The rules
2、 perform FLUSHALL command , It will also trigger RDB The rules , But it doesn't make sense , Because the file content is empty
3、 sign out Redis, There will be dump.rdb file ( sign out Redis Default execution save command )
4、 Use... In the client save perhaps bgsave command , It can also trigger RDB But the two rules are different
save The command will completely occupy the current process for persistence operation , in other words ,save Order just save , No matter what else , As long as there is progress coming , All blocked
bgsave The command runs in the background , Manual fork Child processes operate , And it will respond to the request of the client
3.RDB Data recovery

1、 First, use a Redis Command to view the location where the persistent file is saved
2、 And then dump.rdb Files in Redis Under the startup directory of
4.RDB Advantages and disadvantages
advantage :
1、 Suitable for large-scale data repair .
2、 The requirement for data accuracy is not high .
shortcoming :
1、 A certain time interval is required for persistence , If the server goes down unexpectedly within a certain interval , Then the last persistent data will be lost .
2、 because RDB Persistence is required fork Part of the process IO Operation of the , in other words , Copy an identical process from the original process and run it in memory as a child process , The memory load will double .
AOF
1. What is? AOF
Redis Another way to persist ,AOF, Full name Append Only File, It records every write operation in the form of log , take Redis Record the executed commands ( Reading operation does not record ), Just append files , Do not overwrite the file .Redis It will load automatically at startup AOF Persistent files rebuild data , That is to say Redis Restart will AOF The information in the persistent file is executed from front to back to complete the data recovery .
AOF The location of the configuration file corresponding to persistence is APPEND ONLY MODE
2. start-up AOF

After modifying the configuration , Just restart . if appendonly.aof Some errors occurred in the contents of the file , So in Redis When starting , There will be problems .
Redis Of AOF The name of the persistent file is called appendonly.aof
Here's a little detail to note : If AOF and RDB If the mode is enabled in the configuration file , In order to ensure the security of data , stay Redis It will be used preferentially at startup AOF.
3. Repair AOF file
If appendonly.aof There was an internal error ,Redis Provides a fixable aof The file repair tool is called redis-check-aof

4.AOF Rewriting rule
Rewriting is the merging of commands that can be merged , For example, operate one more time key, Can be merged into one , invalid key All operations can be deleted .
Redis The last rewritten AOF File size is recorded , If the size of the current file is more than twice the size of the source file and the size is greater than 64M Will trigger the rewrite operation .
5.AOF Advantages and disadvantages
advantage :
It supports Synchronous recording and Asynchronous recording , The properties of the corresponding configuration file are as follows :
appendfsync always # Synchronous recording , There is a write operation in the client , Record immediately , Good data integrity , But the performance is poor
appendfsync everysec # Asynchronous recording , Once per second , But if the server goes down within this second , This second of data will be lost
appendfsync no # Don't record , It's also the most efficient
shortcoming :
1、 From a data recovery perspective ,AOF The amount of data recovered must be greater than RDB Big , The repair speed will be slow .
2、 In terms of time to recover data ,AOF Time is also greater than RDB Of .
RDB and AOF The choice of

Be careful :
1、RDB You can persist a snapshot of a dataset within a specified time interval .
2、AOF Persistent records are sent to each client Redis Server write operations , When the server restarts, the command will be executed again to recover the original data ,AOF Each persistent record is appended to the end of the file , also Redis The existence of rewriting mechanism makes AOF The file is controlled at a reasonable size
3、 If Redis Cache only , If you only want the data to exist when the server starts up , You don't have to use any persistence
4、 If both persistence are enabled at the same time ,Redis The server will find first by default AOF Persistence , because AOF It's better to save data sets than RDB To be complete , This is the same. Redis Consider safety reasons .
边栏推荐
- [cloud resident co creation] Huawei iconnect enables IOT terminals to connect at one touch
- Php8.0 environment detailed installation tutorial
- [sword finger offer] 52 The first common node of two linked lists
- Babbitt | yuanuniverse daily must read: minors ask for a refund after a reward. The virtual anchor says he is a big wrongdoer. How do you think of this regulatory loophole
- Post office - post office issues (dynamic planning)
- Another CVPR 2022 paper was accused of plagiarism, and Ping An insurance researchers sued IBM Zurich team
- Redis (V) - advanced data types
- Elastic 8.0: opening a new era of speed, scale, relevance and simplicity
- MySQL advanced - basic index and seven joins
- Research on the principle of Tencent persistence framework mmkv
猜你喜欢

New research of HKUST & MsrA: about image to image conversion, finishing is all you need

Redis (IV) - delete policy

If you want to learn software testing, you must see series, 2022 software testing engineer's career development

火山引擎入选国内首个《边缘计算产业全景图》

Shortcut keys for the rainbow brackets plug-in

元宇宙带来的游戏变革会是怎样的?

Communication network electronic billing system based on SSH

Do you write API documents or code first?

基于eNSP的校园网设计的仿真模拟
![[PROJECT] Xiaomao school (IX)](/img/01/f7fc609e7a156d6e60ce6482ba2ac1.jpg)
[PROJECT] Xiaomao school (IX)
随机推荐
MySQL reports that the column timestamp field cannot be null
Flink系列:checkpoint调优
基于SSM的新闻管理系统
Daily interview 1 question - how to prevent CDN protection from being bypassed
【义修换届大礼包】
ABAP publish restful service
Type ~ storage ~ variable in C #
Small tools (3) integration knife4j3.0.3 interface document
国内离线安装 Chrome 扩展程序的方法总结
Post MSF infiltration summary
Talk about the SQL server version of DTM sub transaction barrier function
Synchronized summary
Openlayers roller shutter map
Volcano engine was selected into the first "panorama of edge computing industry" in China
Conception d'un centre commercial en ligne basé sur SSH
现在玩期货需要注意什么,在哪里开户比较安全,我第一次接触
剑指 Offer 17. 打印从1到最大的n位数
Zero foundation can also be an apple blockbuster! This free tool can help you render, make special effects and show silky slides
Do fresh students get a job or choose a job after graduation?
Word中添加代码块(转载)