当前位置:网站首页>Redis persistence
Redis persistence
2022-06-12 05:41:00 【Xicai pengyuyan】
Redis Persistence
Data security issues , Store memory data on disk , That is, persistence
RDB: memory dump
memory dump : It refers to the status record of data in memory at a certain time .
RDB yes Redis Default persistence scheme in .RDB Persistence writes data from memory to disk , Produce a... In the specified directory dump.rdb file .
Redis Will load on restart dump.rdb File recovery data
Redis Two commands are provided in RDB file . , respectively, save and bgsave.
save: Execute in main process , It can cause congestion
bgsave: Create a subprocess , Quasi user write RDB file , It avoids the blocking of the main thread , The way is RDB Default configuration for file generation 
bgsave Command execution principle
1、 perform bgsave command
2、Redis The parent process in determines whether there are currently executing child processes , If there is , The command returns directly to
3、 The parent process fork Action create subprocess
4、 Parent process completed fork After the operation , The parent process can continue to accept and process user requests , The subprocess is responsible for writing the data in memory to the temporary file on the disk
5、 When the subprocess is finished After all data is written, the old file will be replaced with a temporary file RDB file
Trigger RDB The way
1、 Manual trigger : User execution save perhaps bgsave command
2、 Passive trigger
Automatic snapshot according to configured rules
Format :save
#ave 3600 1 // Every time 3600 Second, at least 1 individual key Change , Take a snapshot
#save 300 100 // Every time 300 Second, at least 10 individual key Change , Take a snapshot
#save 60 10000// Every time 60 Second, at least 10000 individual key Change , Take a snapshot
How to restore RDB file
Only need to RDB Files in Redis Boot directory ,Redis It will be checked automatically when starting dump.rdb Recover the data in the file .
Advantages of memory snapshots
1、RDB load Redis Recover data much faster than AOF The way .
2、 Use separate subprocesses to persist processes , The main process will not do any IO operation , Guarantee Redis A high performance .
Memory snapshot disadvantages
1、RDB Mode data cannot be persisted in real time , There may be data loss issues .
2、 There is a format incompatibility problem ,RDB Files are saved in a specific binary format ,Redis After the version upgrade , There may be old versions Redis Cannot be compatible with the new version RDB Format problem .
AOF(Append Only File) Log files
AOF Persistence , Record each write command in a separate log , Restart of hot wire plating will be performed again AOF The commands in the file achieve the purpose of replying to data .
AOF The main function is to solve the real-time problem of data persistence .
By default Redis It's not turned on AOF Persistence of the way , Can pass appendonly Parameter enable :apendonly yes, Turn on AOF Mode persistence for every command executed ,Redis Will write the command to aof_buff buffer ,AOF The cache will synchronize with the disk according to the corresponding policy
The default is 30 The synchronization operation will be performed once every seconds , In order to prevent the loss of buffer data .
AOF Persistent execution process :
1、 All write commands are appended to AOF buffer
2、AOF The buffer is synchronized to the disk according to the corresponding policy
3、 With AOF The elements of literature are getting bigger and bigger , It needs to be done regularly AOF File rewriting , Achieve the purpose of compressing the file volume ,AOF File rewriting is to Redis The data in the process is converted into write commands to synchronize the new data AOF
4、 When Redis When restarting , Can be loaded AOF File for data recovery
AOF Save the file :appendonly.aof
AOF Write back strategy
AOF The mechanism offers three options , That is, through appendfsync Configure three options
There are three ways , The default is per second everysec Do it once
always: Synchronous write back , Each write command is executed , Write logs back to disk immediately , Ensure complete persistence , The slowest
everysec: Write back every second : After each command is executed , Just write the log first AOF Memory buffer for files , Write buffer data to disk every second
no: Operating system controls writeback : After each command is executed , First write down the journal AOF Memory buffer for files , It is up to the operating system to decide when to write back from the buffer , Best performance , Persistence is no guarantee
AOF Write back policy benefits
1、**AOF Better protect data from loss ,** You can configure the AOFeverysec operation , Once a second , If Redis Hang up , At most 1 Second data
2、AOF In order to Append-only Write the model of , No disk addressing overhead , Write performance is relatively high
AOF Write back policy disadvantages
1、 For the same document AOF File than RDB Big data snapshot
2、 Data recovery is slow
边栏推荐
- GRP development: four communication modes of GRP
- Halcon uses points to fit a plane
- 37. serialized binary tree
- [gpio] how to modify / display GPIO status through ADB shell
- Detailed analysis of the 2021 central China Cup Title A (color selection of mosaic tiles)
- Caused by: org. h2.jdbc. JdbcSQLSyntaxErrorException: Table “USER“ not found; SQL statement:
- Field xxxxDAO in com. nero. hua. service. impl. LoginServiceImpl required a bean of type
- 67. convert string to integer
- Multi thread learning 4. Sleep, wait, yield, join (), ThreadGroup control the running of threads
- Performance test - performance test tool analysis
猜你喜欢

Detailed explanation of data envelopment analysis (DEA) (taking the 8th Ningxia provincial competition as an example)

Available RTMP and RTSP test addresses of the public network (updated in March, 2021)

Halcon 3D 深度图转换为3D图像
![[gin] gin framework for golang web development](/img/15/68c4fd217555f940b3cd3d10fcd54f.jpg)
[gin] gin framework for golang web development

Performance test - GTI application service performance monitoring platform

网络加速谁更猛?CDN领域再现新王者

Multi thread learning 4. Sleep, wait, yield, join (), ThreadGroup control the running of threads

Beginning is an excellent emlog theme v3.1, which supports emlog Pro

Detailed analysis of the 2021 central China Cup Title A (color selection of mosaic tiles)

数据集成框架SeaTunnel学习笔记
随机推荐
Save the object in redis, save the bean in redis hash, and attach the bean map interoperation tool class
UBI details and JFFS2 square FS UBIFS
论文阅读_图神经网络GIN
Introduction to Internet Protocol
[JS knowledge] easily understand JS anti shake and throttling
[daily question on niuke.com] two point search
基于tensorflow的校园绿植识别
登录验证过滤器
WebRTC AEC 流程解析
Word frequency statistics using Jieba database
16. sum of the nearest three numbers
Reason: Canonical names should be kebab-case (‘-‘ separated), lowercase alpha-numeric characters and
[go] Viper reads the configuration file in the go project
Performance & interface test tool - JMeter
FPGA语法的细节
Automated test - dark horse headline test project
Vivado HLS introductory notes
49. ugly number
Reverse linked list
Redis cluster cluster capacity expansion and data migration