当前位置:网站首页>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 .
边栏推荐
- Optimize with netcorebeauty Net core independent deployment directory structure
- 麻烦问下 Flink支持同步数据到 sqlserver么
- Force deduction solution summary 1175- prime number arrangement
- 漏洞复现----38、ThinkPHP5 5.0.23 远程代码执行漏洞
- Do you write API documents or code first?
- 元宇宙带来的游戏变革会是怎样的?
- .NET ORM框架HiSql实战-第一章-集成HiSql
- New research of HKUST & MsrA: about image to image conversion, finishing is all you need
- Vulnerability recurrence ----- 38. Thinkphp5 5.0.23 Remote Code Execution Vulnerability
- [machine learning] K-means clustering analysis
猜你喜欢

Shortcut keys for the rainbow brackets plug-in

Inventory in the first half of 2022: summary of major updates and technical points of 20+ mainstream databases

Simulation of campus network design based on ENSP

Deep understanding of JVM (V) - garbage collection (II)

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

Optimize with netcorebeauty Net core independent deployment directory structure

Tsinghua only ranks third? 2022 release of AI major ranking of Chinese Universities of soft science

What will be the game changes brought about by the meta universe?

MIT科技评论2022年35岁以下创新者名单发布,含AlphaFold作者等

每日面试1题-如何防止CDN防护被绕过
随机推荐
元宇宙带来的游戏变革会是怎样的?
Oneortwo bugs in "software testing" are small things, but security vulnerabilities are big things. We must pay attention to them
Redis (V) - advanced data types
C language structure
If you want to learn software testing, you must see series, 2022 software testing engineer's career development
VScode 状态条 StatusBar
[sword finger offer] 52 The first common node of two linked lists
The secondary menu of the magic article system v5.4.0 supports the optimization of form display
Redis (IX) - enterprise level solution (II)
[cloud resident co creation] Huawei iconnect enables IOT terminals to connect at one touch
麻烦问下 Flink支持同步数据到 sqlserver么
Php8.0 environment detailed installation tutorial
Redis (VIII) - enterprise level solution (I)
基于SSH的客户关系CRM管理系统
DeFi借贷协议机制对比:Euler、Compound、Aave和Rari Capital
Do you write API documents or code first?
Elastic 8.0: opening a new era of speed, scale, relevance and simplicity
Alexnet of CNN classic network (Theory)
New research of HKUST & MsrA: about image to image conversion, finishing is all you need
Flink系列:checkpoint调优