当前位置:网站首页>(2) Docker installs Redis in practice (persistent AOF and RDB snapshots)
(2) Docker installs Redis in practice (persistent AOF and RDB snapshots)
2022-08-11 05:33:00 【Xiao Tan floats in Shanghai】
Body
Why persistence is needed
Redis is an in-memory database.Once the service goes down, all data in memory will be lost.The usual solution is to restore these data from the back-end database, but the back-end database has performance bottlenecks. If it is a recovery of a large amount of data,
1. It will bring huge pressure on the database
2. The performance of the database is not as good as that of Redis.Causes the program to respond slowly.So for Redis, it is crucial to achieve data persistence and avoid restoring data from the back-end database.
Persistence is divided into: AOF and RDB snapshots
RDB snapshot: RDB is the abbreviation of Redis DataBase, the Chinese name is snapshot/memory snapshot. RDB persistence is the process of generating a snapshot of the current process data and saving it to disk. Since it is a snapshot at a certain time, then the snapshot in the snapshotThe value must be earlier than or equal to the value in memory.
AOF storage: Redis is a "post-write" log. Redis executes commands first, writes data into memory, and then records logs.The log records every command received by Redis, and these commands are saved in text form.
The AOF log adopts the log after write, that is, write the memory first, then write the log.
Why log after write?
Redis requires high performance, and using log writing has two advantages:
Avoid additional checking overhead: When Redis logs to AOF, it does not first check the syntax of these commands.Therefore, if you record the log first and then execute the command, the wrong command may be recorded in the log, and Redis may make an error when using the log to restore data.
Does not block the current write operationBut this approach has potential risks:
- If the execution of the command is completed and the machine crashes before writing the log, data will be lost.
- The main thread has a lot of pressure to write to the disk, resulting in slow disk writing and blocking subsequent operations.
How to implement AOF
AOF log records each write command of Redis. The steps are divided into: command append (append), file write (write) and file synchronization (sync).
Command Append When the AOF persistence function is turned on, after the server executes a write command, it will append the executed write command to the server's aof_buf buffer in the protocol format.
File writing and synchronization Redis provides three writeback strategies for when to write the contents of the aof_buf buffer to the AOF file:
Always synchronous writeback: After each write command is executed, the log will be written back to disk synchronously immediately;
Everysec writes back every second: After each write command is executed, just write the log to the memory buffer of the AOF file first, and write the contents of the buffer to the disk every second;
No OS-controlled writeback: After each write command is executed, just write the log to the memory buffer of the AOF file first, and the OS decides when to write the buffer content backdisk.
How to implement AOF storage in Redis!Scroll down
1. Enable AOF persistence
First, you need to enable persistent storage in the redis-master.conf configuration file, and then restart the redis-master master node
1.1 Verify that Redis AOF persistence is enabled successfully
Need to enter the master node to write key value data
1.2 Check whether the key value is saved successfully in AOF
You need to enter the data directory, then find the file with the suffix incr.aof in the appendonlydir folder, and find sex and age in it
2. Turn off AOF persistence
First you need to turn off persistent storage in the redis-master.conf configuration file, and then restart the redis-master master node
2.1 Verify that Redis AOF persistence is closed successfully
Need to enter the master node to write key value data
2.2 Check whether the key value is saved successfully in AOF
You need to enter the data directory, and then find the file with the suffix incr.aof in the appendonlydir folder, whether there are test123 and dcpp456
How to implement RDB storage in Redis!Scroll down
Note: RDB storage does not need to be turned on in the configuration file.
1. Go to the root directory of the redis-master container and find the dump.rdb file.View the file, it is empty
2. Use redis-cli to connect, enter password, and write data
3. After exiting the container with exit, check whether the data exists in the dump.rdb file in the root directory
4, even if dump.rdb is deleted in the data path of the container.Restart the redis-master master node.Then re-enter the container to view the data.Data will also exist.Because Redis data is stored in memory.
All right!The AOF and RDB persistence of Redis has been explained, and the next chapter will explain how Redis performs data migration
边栏推荐
- 面试宝典一: code题目记录
- Solidrun hummingboard制作SD卡
- (二)Docker安装Redis实战(持久化AOF和RDB快照)
- Apache Commons OGNL语法说明_翻译
- 代理模式(简要介绍)
- Decryption of BitLocker
- CentOS7静默安装Oracle11g_转载
- MySQL事务的概念
- Flask框架学习:模板渲染与Get,Post请求
- Redis - Data Types (Basic Instructions, String, List, Set, Hash, ZSet, BitMaps, HyperLogLog, GeoSpatial) / Publish and Subscribe
猜你喜欢
Sub-database sub-table ShardingSphere-JDBC notes arrangement
分库分表之sharding-proxy
第二篇 DS5 Armv8 样例工程报错之GCC编译
Unity WebGL RuntimeError: integer overflow
关于ie下href有中文出现RFC 7230 and RFC 3986问题的研究
0708作业---商品信息
prometheus:(二)监控概述(你永远逃不出我的手掌哈哈)
用白嫖的Adobe正版软件,减少应届毕业生的慢就业、不就业等现象
redis集群模式--解决redis单点故障
Switch and Router Technology-35-NAT to PAT
随机推荐
flask框架学习:debug与配置项
(三)Redis 如何进行压测
ARM结构体系4:嵌入式硬件平台接口开发
postman脚本的应用
Thymeleaf
Django--20实现Redis支持、上下文以及上下文和接口的交互
shell 脚本编程---入门
Redis中RDB和AOF的区别
MySQL数据库管理
用白嫖的Adobe正版软件,减少应届毕业生的慢就业、不就业等现象
什么是三次握手和四次挥手(清晰易懂)
滴滴出行 nlp算法工程师面试经验分享 带offer截图真实
2022建筑焊工(建筑特殊工种)考题及模拟考试
Solidrun hummingboard制作SD卡
将double类型的数据转为字符串
C statement: data storage
Four functional interfaces
基础数据之double和float区别
注解式编程小记
玩转mysql之查看mysql版本号