当前位置:网站首页>06. on several ways of redis persistence
06. on several ways of redis persistence
2022-07-01 01:19:00 【Programmer ah Hong】
Personal home page : Programmer a Hong
Ordinary life , The heart will shine , Years are dreary , Run , There will be wind
Recommended articles :
【 Graduation season · The technique of attack er】 A year after graduation
Java A one-stop version of the learning route
A detailed explanation SpringBoot Global profile
1. RDB
Redis DataBase
- Within a specified time interval , Writes a snapshot of a dataset in memory to disk ;
- The default is saved in /usr/local/bin in , file name dump.rdb;
1.1 Automatic backup
- redis Is a memory database , Every time we run out redis, close linux when , Logically speaking , Memory free ,redis The data in will also disappear
- Why do we start again redis When , Yesterday's data is still , It didn't disappear ?
- Precisely because , Every time you shut down ,redis The data will be automatically backed up to a file :/usr/local/bin/dump.rdb
- Next, let's have a comprehensive understanding Automatic backup mechanism
- The default automatic backup strategy is not conducive to our testing , So modify redis.conf Automatic backup policy in files
vim redis.conf
/SNAP # Search for
save 900 1 # 900 Seconds , At least change 1 Time , Will automatically backup
save 120 10 # 120 Seconds , At least change 10 Time , Will automatically backup
save 60 10000 # 60 Seconds , At least change 10000 Time , Will automatically backup
Of course, if you just use Redis Cache function of , No need to persist , Then you can comment out all the save Line to disable the save function . You can use an empty string to disable :save “”
- Use shutdown Analog shutdown , Before and after shutdown , contrast dump.rdb File update time
Be careful : When we use shutdown command ,redis The database will be backed up automatically , therefore ,dump.rdb The file creation time has been updated
- Boot up redis, We will be having 120 Save in seconds 10 Data , Check it again dump.rdb File update time ( Open two terminals
window , Convenient view ) - 120 Save in seconds 10 The action of data triggers the backup instruction , at present ,dump.rdb In the file 10 Data , take
dump.rdb Copy a dump10.rdb, At this point, both files are saved 10 Data - Now that the data has been backed up , Then we will wantonly delete all the data flushall, Again shutdown To turn it off
- Start again redis, Found that the data really disappeared , Not as we thought take dump.rdb Restore the contents of the file to redis in . Why? ?
because , When we save 10 When more than one piece of data , The data is backed up ;
Then delete the database , Back up the data in the file , Also no problem ;however , The problem is shutdown On , Once this command is executed , It will be backed up immediately , Generate a backup file for the deleted empty database , Put the front into 10 The backup file of data is overwritten . therefore , The result of the above figure appears . Automatically
Recovery failed .How to solve this problem ? Back up the backup file again
- take dump.rdb File deletion , take dump10.rdb Rename it to dump.rdb
- start-up redis service , Sign in redis, data 10 strip , All recovered !
1.2 Manual backup
- Automatic backup before , A lot of data has to be changed , For example, above , We changed more than ten pieces of data , Will automatically backup ;
- Now? , I only save one piece of data , Just want to back up immediately , What to do ?
- Each operation is completed , Carry out orders save It will be backed up immediately
1.3 And RDB Related configuration
- stop-writes-on-bgsave-error: Water inlet and outlet , Whether the water outlet fails or not
- yes: When the background backup is wrong , The foreground stops writing
- no: Dead or alive , It's going in
- rdbcompression: For snapshots stored on disk , Whether to start LZF Compression algorithm , It usually starts , Because of this performance , Buy an extra computer , It's all done N Back and forth .
- yes: start-up
- no: Do not start ( Don't want to consume CPU resources , Can be turned off )
- rdbchecksum: After storing the snapshot , Whether to start CRC64 Algorithm for data validation ;
- After opening , About increase 10% Left and right CPU Consume ;
- If you want to get the most performance improvement , Can choose to close
- dbfilename: Snapshot backup file name
dir: The directory where the snapshot backup file is saved , Default to current directory
advantage and Inferiority
- optimal : Suitable for large-scale data recovery , The requirements for data integrity and consistent rows are not high ;
- inferior : Back up at regular intervals , accident down fall , You lose all the changes of the last snapshot
2. AOF
Append Only File
- Log every write operation ;
- take redis All write instructions executed are recorded ( Reading operation does not record );
- Only additional documents are allowed , You cannot overwrite the file ;
- redis At the beginning of startup, the file will be read and executed from beginning to end , To rebuild the data ;
2.1 Turn on AOF
- To avoid mistakes , It is best to redis.conf Back up the general configuration file , Then modify the content as follows :
appendonly yes
appendfilename appendonly.aof
- Restart redis, Start with a new profile
redis-server /usr/local/redis5.0.4/redis.conf
Connect redis, Add data , Delete library , sign out
View the current folder one more aof file , Look at the contents of the file , It's all preserved Write operation
- The last sentence in the file should be deleted , Otherwise, the data cannot be recovered
- Edit this file , Finally :wq! Enforcement
Just reconnect , Data recovery successful
2.2 coexistence ? Who is the first ?
We see the redis.conf file ,AOF and RDB Both backup strategies can be turned on at the same time , How will the system choose ?
- Try it , edit appendonly.aof, Fooling around , Save and exit
- start-up redis Failure , So it is AOF Load first to recover the original data ! because AOF Than RDB The integrity of data preservation is higher !
- Repair AOF file , Killing all is not in line with redis The code of the grammar specification
reids-check-aof --fix appendonly.aof
2.3 And AOF Related configuration
- appendonly: Turn on aof Pattern
- appendfilename:aof File name of , Better not change !
- appendfsync: Follow up strategy
- always: Every data change , It will be recorded to disk immediately , Poor performance , But the data integrity is good
- everysec: default setting , Asynchronous operations , Record every second , If it goes down in a second , There will be data loss
- no: Don't follow up
- no-appendfsync-on-rewrite: Whether to use Appendfsync Follow up strategy ; Use default no that will do , Data security .
- AOF By means of document addition , The file will get bigger and bigger , To solve this problem , Added rewriting mechanism ,redis Will automatically record the last AOF File size , When AOF When the file size reaches the preset size ,redis Will start AOF File content compression , Keep only the smallest set of instructions that can recover data
- auto-aof-rewrite-percentage: If AOF The file size has exceeded the original size 100%, That's double , Just rewrite the compression
- auto-aof-rewrite-min-size: If AOF The file has exceeded 64mb, Just rewrite the compression
3 summary ( How to choose ?)
- RDB: For backup purposes only , Suggest 15 Just back up once a minute
- AOF:
- In the worst case , Only no more than 2 Second data , Data integrity is relatively high , But the price is too high , Will bring lasting IO
- The size of the hard disk is also high , Default 64mb Is too small , The enterprise level is at least 5G above ;
- master/slave Is the choice of sina Weibo !!
End of the flower
If fate is the worst screenwriter in the world . Then you have to fight for , Be the best actor in your life
Writing is not easy to , If you think , Welcome to praise the blogger 、 Collection 、 A wave of comments ~ Let bloggers have more motivation
边栏推荐
- 染色法判断二分图
- High quality pump SolidWorks model material recommended, not to be missed
- The real topic of the 11th provincial competition of Bluebridge cup 2020 - crop hybridization
- 机器人编程的培训学科类原理
- 機器人編程的培訓學科類原理
- 软件开发完整流程
- Vnctf 2022 cm CM1 re reproduction
- DX-11Q信号继电器
- A proper job is a good job
- Document service design
猜你喜欢

用recyclerReview展示Banner,很简单

For the first time in more than 20 years! CVPR best student thesis awarded to Chinese college students!

Install redis database and download redis Desktop Manager in win11

Gavin's insight on the transformer live broadcast course - rasa project's actual banking financial BOT Intelligent Business Dialogue robot system startup, language understanding, dialogue decision-mak

New content violation degree determination scana bad information monitoring capability update issue 5
![[original] PLSQL index sorting optimization](/img/91/dcd0262705a19645f1a87d4cf03bc8.jpg)
[original] PLSQL index sorting optimization
![Parity linked list [two general directions of linked list operation]](/img/4e/ce860bc172bb75f456427ba26a7842.png)
Parity linked list [two general directions of linked list operation]

Implementation of date class

人穷志不短,穷学生也能玩转树莓派

孔乙己第一问之服务通信知多少?
随机推荐
2022 is half way through. It's hard to make money
[LeetCode] 两数之和【1】
Q play soft large toast to bring more comfortable sleep
[LeetCode] 爬楼梯【70】
Some views on libco
Gavin's insight on the transformer live broadcast course - rasa project's actual banking financial BOT Intelligent Business Dialogue robot system startup, language understanding, dialogue decision-mak
MATLAB 最远点采样(FPS改进版)
用recyclerReview展示Banner,很简单
Exercises on recursion in C language
PHP online confusion encryption tutorial sharing + basically no solution
Using C language to realize the exchange between the contents of two arrays (provided that the array is the same size)
Day31-t1380-2022-02-15-not answer by yourself
Locking relay ydb-100, 100V
Openmv and k210 of the f question of the 2021 video game call the openmv API for line patrol, which is completely open source.
DLS-20型双位置继电器 220VDC
ESP8266 RC522
奇偶链表[链表操作的两种大方向]
Analyzing the wisdom principle in maker education practice
Docker deployment MySQL 8
js中把数字转换成汉字输出