当前位置:网站首页>[Redis] Redis穿透、雪崩和击穿
[Redis] Redis穿透、雪崩和击穿
2022-07-27 17:26:00 【大佬,菜菜,带带】
穿透
定义:
穿透是指请求的数据在Redis缓存中和数据库中都没有,所以数据库返回了一个空数据,Redis也不会进行缓存,每次请求的数据都会查询数据库。
解决方法:
- Redis对数据库返回的空数据也进行缓存,并设置一个合理的过期时间,这样再请求时就可以从缓存中拿到数据。
- 设置布隆过滤器(Bloom Filter),作用是对于请求的数据先进行筛选,拦截对不存在的数据的请求,存在的数据放行到Redis。
雪崩
定义:
雪崩是指大量的请求数据(不相同)查询Redis时Redis坏了或者数据同时过期,导致请求直接打在数据库上导致数据库崩溃。
解决方法:
- 设置多级的缓存:nginx缓存 Redis缓存。
- 设置灾难预警机制:定期检查Redis服务器状态等。
- 数据过期时间设置为固定值+随机值,尽可能的将过期时间分散。
- 限流降级(不推荐)
- 限流:限制请求数据库的请求数量
- 降级:对于一些热点数据保存在内存中,当Redis故障时直接查询内存
- 对于热点数据设置为永不过期
- 自动/人工检查过期数据,决定是否延期。
击穿
定义:
击穿是指大量请求同一个数据,但是这时候Redis中此数据过期,导致请求直接打在数据库上导致数据库崩溃。
解决方法:
- 分布式锁,只允许一个请求查询数据库,其他请求延时。
- 对于热点数据设置永不过期。
- 自动/人工检查过期数据,决定是否延期。
- 数据预热,对于热点数据提前保存到缓存中。
边栏推荐
猜你喜欢

Online Judge 输出超限

SystemService(系统服务)

PC博物馆(3) MITS Altair 8800

focal loss

化工巨头巴斯夫&Pasqal:利用量子神经网络优化天气预报

ToggleButton(按钮开关)

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte

VS2017#include 'xxx.h'

GestureDetector(手势识别)
![[basic knowledge of deep learning - 42] detailed explanation of logistic regression](/img/74/d7d1562ada4671864961721b9a1baf.png)
[basic knowledge of deep learning - 42] detailed explanation of logistic regression
随机推荐
vlan试验2021.1.14
Intel launched the world's smallest high-resolution lidar, priced at only $349
Intel's process roadmap for the next 10 years is exposed: 1.4nm process will be launched in 2029! How?
Fileoutputstream (file storage) and FileInputStream (file reading)
Detailed interpretation of IEC104 protocol (I) protocol structure
Online Judge 输出超限
[Huawei cloud stack] [shelf presence] issue 13: have you seen the decoupling architecture of the management area? Help government and enterprise customers solve big problems
In a real case, college students were cheated when taking orders. I hope you won't be cheated [painful lesson]
[basic knowledge of deep learning - 38] the difference between L1 regularization and L2 regularization
JS 事件监听 鼠标 键盘 表单 页面 onclick onkeydown onChange
C#求完全数,输出水仙花以及类的使用
Container summary
Matplotlib (basic usage)
ContextMenu (context menu)
VLAN test 2021.1.14
顶级“黑客”能厉害到什么地步?无信号也能上网,专家:高端操作!
Oracle XE版安装与用户操作
Adults have only one main job, but they have to pay a price. I was persuaded to step back by personnel, and I cried all night
Global function
Marqueetextview (running lantern)