当前位置:网站首页>Redis-緩存問題
Redis-緩存問題
2022-06-30 12:28:00 【Array_new】
前言:
每次啟動項目時都會由於數據庫的數據太多導致剛進去的時候會由於數據存放過多,首頁信息多個請求體直接用MySQL數據庫速度慢,影響用戶體驗一下是用redis解决緩存問題的解决思路,以提高能。
緩存穿透
指的是客戶端請求的數據在緩存中和數據庫中都不存在,這樣的緩存永遠也不會生效,這些請求都會打到數據庫
問題解决:
- 緩存空對象
優點:實現簡單,維護方便
缺點:額外內存消耗,可能造成短期的不一致

2.布隆過濾
優點:內存占用少,沒有多餘的Key
缺點:實現複雜,存在誤判可能

緩存擊穿
緩存擊穿是指用戶查詢的數據緩存中不存在,但是後端數據庫卻存在,這種現象出現原因是一般是由緩存中 key 過期導致的。比如一個熱點數據 key,它無時無刻都在接受大量的並發訪問,如果某一時刻這個 key 突然失效了,就致使大量的並發請求進入後端數據庫,導致其壓力瞬間增大。這種現象被稱為緩存擊穿。
緩存擊穿有兩種解决方法:
1) 改變過期時間
設置熱點數據永不過期。
2) 分布式鎖
采用分布式鎖的方法,重新設計緩存的使用方式,過程如下:
- 上鎖:當我們通過 key 去查詢數據時,首先查詢緩存,如果沒有,就通過分布式鎖進行加鎖,第一個獲取鎖的進程進入後端數據庫查詢,並將查詢結果緩到Redis 中。
- 解鎖:當其他進程發現鎖被某個進程占用時,就進入等待狀態,直至解鎖後,其餘進程再依次訪問被緩存的 key。
緩存雪崩
緩存雪崩是指緩存中大批量的 key 同時過期,而此時數據訪問量又非常大,從而導致後端數據庫壓力突然暴增,甚至會掛掉,這種現象被稱為緩存雪崩。它和緩存擊穿不同,緩存擊穿是在並發量特別大時,某一個熱點 key 突然過期,而緩存雪崩則是大量的 key 同時過期,因此它們根本不是一個量級。
解决方案
緩存雪崩和緩存擊穿有相似之處,所以也可以采用熱點數據永不過期的方法,來减少大批量的 key 同時過期。再者就是為 key 設置隨機過期時間,避免 key 集中過期。
边栏推荐
- 品达通用权限系统(Day 7~Day 8)
- [cloud native | kubernetes] in depth understanding of deployment (VIII)
- Construction de la plate - forme universelle haisi 3559: obtenir le codage après modification du cadre de données
- Splitting e-commerce systems into micro services
- Vscode select multiple words
- A Generic Deep-Learning-Based Approach for Automated Surface Inspection-论文阅读笔记
- 海思3559万能平台搭建:获取数据帧修改后编码
- Constructor, class member, destructor call order
- ModelAtrs声音检测,基于声学特征的异响检测
- Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance
猜你喜欢

A review of quantum neural networks 2022 for generating learning tasks

Building of Hisilicon 3559 universal platform: obtaining the modified code of data frame

SuperMap 3D SDKs_Unity插件开发——连接数据服务进行SQL查询

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

How to detect 3D line spectral confocal sensors in semiconductors

Building a database model using power designer tools

Redis-缓存问题

ES6新特性介绍

MySQL composite query

NoSQL - redis configuration and optimization
随机推荐
视频按每100帧存一个文件夹,处理完再图片转视频
Statistics on the number of closed Islands
Hisilicon 3559 universal platform construction: introduction to YUV format
Splitting e-commerce systems into micro services
ModelAtrs声音检测,基于声学特征的异响检测
Embedded sig | multi OS hybrid deployment framework
List集合
1020. number of enclaves
edusoho企培版纯内网部署教程(解决播放器,上传,后台卡顿问题)
MySQL索引和优化的理解学习
90. (cesium chapter) cesium high level listening events
Map collection
使用Power Designer工具构建数据库模型
串行通信接口8250
Generate entity classes from SQL Server database tables through EF core framework
What is the principle of spectral confocal displacement sensor? Which fields can be applied?
品达通用权限系统(Day 7~Day 8)
Swagger2自动生成APi文档
Substrate 源码追新导读: 5月中旬: Uniques NFT模块和Nomination Pool
A Generic Deep-Learning-Based Approach for Automated Surface Inspection-论文阅读笔记