当前位置:网站首页>Redis data persistence
Redis data persistence
2022-06-13 04:14:00 【Doodle programmer excrement Officer】
The contents of this blog article :
1. What is data persistence
Redis All data is saved in memory , If you do not do any persistence operation, when Redis Data loss on shutdown , Data persistence is to prevent data loss ,Redis Will asynchronously save data on the hard disk .

2. Data persistence
- RDB( Snapshot mode )

- AOF( How to log )

3.Redis Data persistence -RDB
Redis Save data to disk in binary form , The saved file is suffixed with rdb, Load the next time you start rdb File recovery data , To achieve persistence .

(1) Trigger RDB The way
- Automatic mode
Through the relevant configuration in the configuration file ,Redis Automatic persistence according to the configuration .
RDB Configuration item information for :

Enter the directory where the configuration file is located , And pass Vim Command to edit 
RDB The configuration information is as follows :
Configuration details :
save 60 1
dbfilename dbdump.rdb
dir /usr/local/redis-6.0.6/
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
remarks :save 60 1 Express 60s There is a key Save changes , It's a strategy , Multiple policies can be set at the same time , as follows :

start-up Redis Server side :
adopt RDM In the db2 Add a message to the database key = Java value=best! The data of 

We will find that Redis There is one more... In the catalog dbdump.rdb The file of

adopt Vim see dbdump.rdb file , There will be data in it , But it's a mess , Understandable because Redis Save in binary 
.
take Redis Server shutdown , Then start again to see if the data still exists :
We will find that the data still exists , Data persistence succeeded !
- Manual mode
When it comes to persistence , Input save or bgsave Command persistence (
Are single thread blocking , This means that no other commands can be executed while saving),save and bgsave Orders are essentially the same , One runs synchronously and the other runs asynchronously , But they are all single thread blocking .


(2) RDB The shortcomings of

4.Redis Data persistence -AOF
Use the log method to add and save the command of each step of our operation to the disk , The format actually saved here is not the command format , It's a specific format , The file suffix is AOF, Data recovery will AOF File loading .
(1) Log an additional - AOF

(2) Log recovery

(3) AOF The addition of (fsync) Strategy
appendfsync Append strategy ( Such as :appendfsync everysec)

(4) AOF Three ways to compare

(5) AOF rewrite
Only care about the final state , Save the command executed in the current latest state , For example, in the following table set hello world ,set hello java and set hello hehe The last status of the command is set hello hehe The state in which the command is executed , So these three commands only save set hello hehe command , The same is true of other orders , So finally AOF The command saved after rewriting is set hello hehe ,set counter 2 and rpush mylist a b c These three orders .

(6) AOF How to implement
- Automatic mode ( Use AOF Override configuration mode )
AOF Rewrite the configuration options as follows :
Shut down first Redis Server side :
And then through vim Command to edit Redis Configuration file for , newly added Aof Configuration of :
Configuration details :
appendonly yes
appendfilename aof-6666.aof
appendfsync everysec
no-appendfsync-on-rewrite yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
Start again Redis Server side :
adopt RDM Add to database 2 Add a piece of data key=PHP value=Java
We will find that Redis There is one more... In the catalog aof-6666.aof The file of 
We go through vim Command to view the file :
About rewrite explain 
- Manual mode ( Use bgrewriteaof Command mode )

5.RDB And AOF The choice of
( AOF The load priority of is compared to RDB Higher )
边栏推荐
- [zeloengine] localization process /imgui Chinese culture
- SCM signal generator program
- 环评图件制作-数据处理+图件制作
- 1.4.2 Capital Market Theroy
- Redis-HyperLogLog-基数统计算法
- VGA display based on de2-115 platform
- Lambda end operation find and match findany
- Student management system
- 单片机外设介绍:温度传感器 DS18B20
- Interpretation and implementation of proxy mode
猜你喜欢

Sword finger offer II 022 Entry node of a link in a linked list

The could not find com scwang. smart:refresh-layout-kernel:2.0.3. Required by: project: the app cannot load the third-party package

SCM signal generator program
![[MySQL] index and transaction](/img/19/f87fee3749690902c349c42673f148.png)
[MySQL] index and transaction

MCU: pcf8591 hardware interface

The most detailed swing transformer mask of window attachment in history -- Shaoshuai

No more! Another member of the team left..

Single chip microcomputer: pcf8591 application program

Fundamentals of robot obstacle avoidance system

Unity shader learning 004 shader debugging platform difference third-party debugging tools
随机推荐
Redis hyperloglog cardinality statistics algorithm
The WebView case of flutter
Lambda termination operation find and match nonematch
[test development] file compression project practice
Real time requirements for 5g China Unicom repeater network management protocol
[笔记]vs2015 编写汇编masm32之使用MASM32库
EGO planner论文翻译
MCU: RS485 communication and Modbus Protocol
Single chip microcomputer: pcf8591 application program
剑指 Offer 11. 旋转数组的最小数字-二分查找
Value of line height
On the value of line height
LVS four layer load balancing cluster (3) cluster function classification - HPC
[kubernetes series] pod chapter actual operation
UE4 learning notes - functions of terrain tool
1.4.2 Capital Market Theroy
Line height equals height why not center
【LeetCode】860. Change with lemonade (2 brushes for wrong questions)
Summary of meeting between president Ren and scientists and experts in system engineering
LVS 4 - tier Load Balancing Cluster (3) Cluster Function Classification - HPC