当前位置:网站首页>Redis-缓存问题
Redis-缓存问题
2022-06-30 12:01:00 【Array_new】
前言:
每次启动项目时都会由于数据库的数据太多导致刚进去的时候会由于数据存放过多,首页信息多个请求体直接用MySQL数据库速度慢,影响用户体验一下是用redis解决缓存问题的解决思路,以提高能。
缓存穿透
指的是客户端请求的数据在缓存中和数据库中都不存在,这样的缓存永远也不会生效,这些请求都会打到数据库
问题解决:
- 缓存空对象
优点:实现简单,维护方便
缺点:额外内存消耗,可能造成短期的不一致

2.布隆过滤
优点:内存占用少,没有多余的Key
缺点:实现复杂,存在误判可能

缓存击穿
缓存击穿是指用户查询的数据缓存中不存在,但是后端数据库却存在,这种现象出现原因是一般是由缓存中 key 过期导致的。比如一个热点数据 key,它无时无刻都在接受大量的并发访问,如果某一时刻这个 key 突然失效了,就致使大量的并发请求进入后端数据库,导致其压力瞬间增大。这种现象被称为缓存击穿。
缓存击穿有两种解决方法:
1) 改变过期时间
设置热点数据永不过期。
2) 分布式锁
采用分布式锁的方法,重新设计缓存的使用方式,过程如下:
- 上锁:当我们通过 key 去查询数据时,首先查询缓存,如果没有,就通过分布式锁进行加锁,第一个获取锁的进程进入后端数据库查询,并将查询结果缓到Redis 中。
- 解锁:当其他进程发现锁被某个进程占用时,就进入等待状态,直至解锁后,其余进程再依次访问被缓存的 key。
缓存雪崩
缓存雪崩是指缓存中大批量的 key 同时过期,而此时数据访问量又非常大,从而导致后端数据库压力突然暴增,甚至会挂掉,这种现象被称为缓存雪崩。它和缓存击穿不同,缓存击穿是在并发量特别大时,某一个热点 key 突然过期,而缓存雪崩则是大量的 key 同时过期,因此它们根本不是一个量级。
解决方案
缓存雪崩和缓存击穿有相似之处,所以也可以采用热点数据永不过期的方法,来减少大批量的 key 同时过期。再者就是为 key 设置随机过期时间,避免 key 集中过期。
边栏推荐
- Joplin implements style changes
- Subtrate 源码追新导读-5月上旬: XCM 正式启用
- VScode选中多个单词
- Go 语言入门很简单:Go 处理 XML 文件
- Building of Hisilicon 3559 universal platform: obtaining the modified code of data frame
- Edusoho enterprise training version intranet only deployment tutorial (to solve the problems of player, upload and background jam)
- Multiparty cardinality testing for threshold private set-2021: Interpretation
- DMA控制器8237A
- List collection
- 200. 岛屿数量
猜你喜欢

How difficult is data governance and data innovation?

AGCO AI frontier promotion (6.30)

Redis6 learning notes - Chapter 2 - Basic redis6 operations

Map集合

麒麟软件韩乃平:数字中国建设需要自己的开源根社区

【云原生 | Kubernetes篇】深入了解Deployment(八)

Four Misunderstandings of Internet Marketing

海思3559万能平台搭建:获取数据帧修改后编码

Lichuang EDA learning notes 10 common connector component identification and passive buzzer driving circuit

A review of quantum neural networks 2022 for generating learning tasks
随机推荐
200. 岛屿数量
剑指 Offer 05. 替换空格: 把字符串 s 中的每个空格替换成“%20“
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram and use scale_ color_ viridis_ D function specifies the color scheme of data points
A Generic Deep-Learning-Based Approach for Automated Surface Inspection-論文閱讀筆記
qt msvc 安装及调试
3D线光谱共焦传感器在半导体如何检测
Solve the problem that the server cannot be connected via SSH during reinstallation
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
[cf] 803 div2 A. XOR Mixup
MATLAB中polarplot函数使用
Subtrate 源码追新导读-5月上旬: XCM 正式启用
并行接口8255A
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram and use scale_ x_ The log10 function configures the value range of the X axis to be logarithmic coordinates
Beego development blog system learning (II)
90. (cesium chapter) cesium high level listening events
立创 EDA #学习笔记10# | 常用连接器元器件识别 和 无源蜂鸣器驱动电路
各厂家rtsp地址格式如下:
1175. prime number arrangement: application of multiplication principle
beego开发博客系统学习(二)
Hisilicon 3559 universal platform construction: introduction to YUV format