当前位置:网站首页>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 集中过期。
边栏推荐
- [cf] 803 div2 B. Rising Sand
- Getting started with the go language is simple: go handles XML files
- STM32 porting the fish component of RT thread Standard Edition
- Building of Hisilicon 3559 universal platform: obtaining the modified code of data frame
- ZABBIX monitors the number of TCP connections
- What is the principle of spectral confocal displacement sensor? Which fields can be applied?
- 海思3559万能平台搭建:获取数据帧修改后编码
- iServer发布ES服务查询设置最大返回数量
- The format of RTSP address of each manufacturer is as follows:
- 用宝塔建第2个网站时网站总是报错:No input file specified.
猜你喜欢
Redis的基本操作的命令
Map collection
Talk about how to do hardware compatibility testing and quickly migrate to openeuler?
QT MSVC installation and commissioning
Swagger2自动生成APi文档
使用Power Designer工具构建数据库模型
Introduction to new features of ES6
A high precision positioning approach for category support components with multiscale difference reading notes
【云原生 | Kubernetes篇】深入了解Deployment(八)
AGCO AI frontier promotion (6.30)
随机推荐
Embedded sig | multi OS hybrid deployment framework
A High-Precision Positioning Approach for Catenary Support Components With Multiscale Difference阅读笔记
SuperMap 3D SDKs_Unity插件开发——连接数据服务进行SQL查询
Pinda general permission system (day 7~day 8)
1020. 飞地的数量
Swagger2 automatically generates API documents
Go 语言入门很简单:Go 处理 XML 文件
Ensemble de cartes
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram, and_ Set show in the point parameter_ The legend parameter is false, and the legend information is not displayed
Biological network analysis using deep learning
【LeetCode】15、三数之和
立创 EDA #学习笔记10# | 常用连接器元器件识别 和 无源蜂鸣器驱动电路
What is the principle of spectral confocal displacement sensor? Which fields can be applied?
[cloud native | kubernetes] in depth understanding of deployment (VIII)
Multiparty cardinality testing for threshold private set-2021: Interpretation
ES6新特性介绍
Building a database model using power designer tools
Lichuang EDA learning notes 10 common connector component identification and passive buzzer driving circuit
海思3559萬能平臺搭建:獲取數據幀修改後編碼
Statistics on the number of closed Islands