当前位置:网站首页>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 集中過期。
边栏推荐
- Swagger2 automatically generates API documents
- AGCO AI frontier promotion (6.30)
- 通过EF Core框架根据SQL Server数据库表生成实体类
- 不同类型的变量与零究竟是如何比较
- 视频按每100帧存一个文件夹,处理完再图片转视频
- Redis-缓存问题
- Typescript readonlyarray (read only array type) details
- NoSQL - redis configuration and optimization
- 【目标跟踪】|pytracking 配置 win 编译prroi_pool.pyd
- Go zero micro Service Practice Series (VIII. How to handle tens of thousands of order requests per second)
猜你喜欢

Introduction to new features of ES6

What are the applications of 3D visual inspection in production flow

Map集合

90.(cesium篇)cesium高度监听事件

Commands for redis basic operations

3D视觉检测在生产流水的应用有哪些

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

Embedded SIG | 多 OS 混合部署框架

Swagger2自动生成APi文档

Joplin implements style changes
随机推荐
使用Power Designer工具构建数据库模型
Talk about how to do hardware compatibility testing and quickly migrate to openeuler?
Solve the problem that the server cannot be connected via SSH during reinstallation
Go zero micro Service Practice Series (VIII. How to handle tens of thousands of order requests per second)
edusoho企培版纯内网部署教程(解决播放器,上传,后台卡顿问题)
A Generic Deep-Learning-Based Approach for Automated Surface Inspection-論文閱讀筆記
Building a database model using power designer tools
Embedded SIG | 多 OS 混合部署框架
lvgl 小部件样式篇
Getting started with the go language is simple: go handles XML files
ZABBIX monitors the number of TCP connections
60 个神级 VS Code 插件!!
[cloud native | kubernetes] in depth understanding of deployment (VIII)
695.最大岛屿面积
视频按每100帧存一个文件夹,处理完再图片转视频
What is the principle of spectral confocal displacement sensor? Which fields can be applied?
Layout of pyqt5 interface and loading of resource files
How difficult is data governance and data innovation?
STM32 porting the fish component of RT thread Standard Edition
通过EF Core框架根据SQL Server数据库表生成实体类