当前位置:网站首页>Double write consistency of MySQL and redis
Double write consistency of MySQL and redis
2022-07-29 02:35:00 【Meme_ xp】
What is the double write consistency problem ?
Look at us first redis Read process :
(1) First reading cache, If the data hits, it returns
(2) If the data misses, read db
(3) take db The data read out in the cache
Strategy 1: Update cache first , Update the database
If the update cache succeeds, the database update fails , Then it will cause cache dirty data
Strategy 2: Update the database first , Update the cache again
This happens in high concurrency :

Threads A New database , Because of the Internet or something , At this time, there is no time to update the cache , The thread updates the database , And updated the cache , however A New cache . Cause our thread B New lost
Strategy 3: So let's delete the cache , Update the database
Delete the cache first and then update the database , This is the mitigation strategy 2 Cache update loss of , But it may still be inconsistent
A To delete the cache ,B Read operation , Discover again redis No hits in , therefore B The thread is going to read from the database , And write this data to redis in , Then the thread A Finish updating the database , Database and redis Cache inconsistency

How to solve :
Just in the thread A After updating the database , And then delete One cache , This is called delayed double deletion , The delay time here must be greater than the reading time of our business
Strategy 4: Update the database first , Delete the cache
When we A Query data , Preparing to write to the cache , Threads B Updated database , Then the cache is deleted , then A Before writing the previous old value to redis. The probability of occurrence is very low , Because the write operation time is more likely than the read operation time
resolvent :
Delay double delete , But what if the deletion fails ?
Then it will be deleted repeatedly , We can delete key Put in queue , Then repeat the attempt to delete , Until success
边栏推荐
- How much is the report development cost in the application system?
- 如何把thinkphp5的项目迁移到阿里云函数计算来应对流量洪峰?
- 聊聊 Feign 的实现原理
- Full solution of 3D model format | including more than 70 kinds of RVT, 3ds, DWG, FBX, IFC, osgb, obj, etc
- 网络安全漏洞管理的探索与实践
- I was stunned by this question that I browsed 746000 times
- Chapter 3 business function development (deletion and modification of clue remarks)
- [RT learning note 1] RT thread peripheral routine - control LED light flashing
- What if there is not enough time for adequate testing?
- 响应式织梦模板化妆美妆类网站
猜你喜欢

After 4 years of testing experience, I finally entered Alibaba. Two months later, I chose to resign naked

“12306”的架构到底有多牛逼?

详解异步任务:任务的状态及生命周期管理

Object based real-time spatial audio rendering - Dev for dev column

The outsourcing company "mixed" for two years, and I only did five things seriously. Now I get byte offer smoothly.

外包公司“混”了2年,我只认真做了5件事,如今顺利拿到字节 Offer。

一文理解分布式开发中的服务治理

Understand the evolution of redis architecture in one article

When synchronized encounters this thing, there is a big hole, so be careful

如何快速设计一套支持渲染富文本内容的跨端组件
随机推荐
深度剖析 —— 预处理
Meeting notice of meeting OA
Production scheme and advantages of online 3D digital exhibition hall
The outsourcing company "mixed" for two years, and I only did five things seriously. Now I get byte offer smoothly.
Redis主从模式、哨兵集群、分片集群
3d智能工厂工艺流转可视化交互展示应用优点
3种过期策略
Jmeter之BeanShell生成MD5加密数据写入数据库
发布融资需求1.29亿元,大科城项目路演持续浇灌科创“好苗子”
Altium designer outputs Gerber and other production documents
Thermistor temperature calculation formula program
Awvs cannot start problem
C语言实现三子棋游戏
响应式织梦模板家装建材类网站
应用系统中的报表开发成本值多少?
What should I do if excel opens a CSV file containing Chinese characters and there is garbled code?
Day 15 (VLAN related knowledge)
2022/07/28 学习笔记 (day18) 常用API
裂开了,一次连接池参数导致的雪崩问题
QT qstackedwidget multi interface switching