当前位置:网站首页>redis和mysql数据不一致问题如何解决?
redis和mysql数据不一致问题如何解决?
2022-06-28 13:03:00 【知其黑、受其白】
解决思路
要解决缓存数据不一致的问题,首先要理解为什么缓存和数据库会存在不一致的情况。
什么情况下缓存和数据库会不一致?
在高并发的情况下,如果所有的数据都从数据库中去读取,那再强大的数据库系统都承受不了这个压力,因此我们会将部分数据放入缓存中,比如放入redis中。
这是典型的用空间换时间的方式。
但是这个redis相当于是真实数据的一个副本,这就意味着如果数据库中数据发生变化的时候,就会导致缓存数据不一致的问题。
归根结底,只要有两份数据存在,数据一致性问题就是不可避免的。
解决方法
方法1:数据实时更新
当更新数据库的时候,同步更新缓存。
优点:数据一致性强,不会出现缓存雪崩的问题。
缺点:代码耦合度高,影响正常业务,增加一次网络开销。
适用环境:适用于数据一致性要求高的场景,比如银行业务,证券交易等。
边栏推荐
猜你喜欢

VS2012 VC新建一个空白窗口应用

从pdb源码到frame帧对象

How to find opportunities in a bear market?

数启扬帆,智聚人才 | 腾讯云数据库 & CSDN 工程师能力轻量认证发布会重磅来袭!...

Flink stream processing API collection: master all Flink stream processing technologies. Just read this article

Shareit a une force exceptionnelle et se connecte au top 7 de la liste mondiale des forces IAP

【历史上的今天】6 月 28 日:马斯克诞生;微软推出 Office 365;蔡氏电路的发明者出生

腾讯汤道生:面向数实融合新世界,开发者是最重要的“建筑师”

Fastposter v2.8.4 release e-commerce poster generator

ASP. NET CORE Study09
随机推荐
Tencent tangdaosheng: facing the new world of digital and real integration, developers are the most important "architects"
go template with...end遍历用法
思源官方付费同步使用指南
小白创业做电商,选对商城系统很重要!
Deep understanding of Bayes theorem
专业英语历年题
Copying open source for basic software is not advisable. Self reliance is the right way
Implementation of fruit and vegetable mall management system based on SSM
VS2012 VC新建一个空白窗口应用
Fastposter v2.8.4 release e-commerce poster generator
Performance test-01-introduction
从 jsonpath 和 xpath 到 SPL
fastposter v2.8.4 发布 电商海报生成器
一款自动生成单元测试的 IDEA 插件,开发效率提升 70% 以上!
[cloud native] can self-service reports and Bi do so many things?
ShareIt has outstanding strength and landed in the top 7 of the global IAP strength list
ASP. NET CORE Study03
关于IP定位查询接口的测评Ⅰ
Vs2012 VC creates a new blank window application
Understand leveldb write operation