当前位置:网站首页>Redis缓存穿透
Redis缓存穿透
2022-06-10 19:56:00 【飞Link】
一、问题描述
key对应的数据在数据源并不存在,每次针对此key的请求从缓存获取不到,请求都会压到数据源,从而可能压垮数据源。比如用一个不存在的用户id获取用户信息,不论缓存还是数据库都没有,若黑客利用此漏洞进行攻击可能压垮数据库

二、解决方案
一个一定不存在缓存及查询不到的数据,由于缓存是不命中时被动写的,并且出于容错考虑,如果从存储层查不到数据则不写入缓存,这将导致这个不存在的数据每次请求都要到存储层去查询,失去了缓存的意义
解决方案:
1. 对空值缓存
如果一个查询返回的数据为空(不管是数据是否不存在),我们仍然把这个空结果(null)进行缓存,设置空结果的过期时间会很短,最长不超过五分钟
2. 设置可访问的名单(白名单)
使用bitmaps类型定义一个可以访问的名单,名单id作为bitmaps的偏移量,每次访问和bitmap里面的id进行比较,如果访问id不在bitmaps里面,进行拦截,不允许访问
3. 采用布隆过滤器
- 布隆过滤器(Bloom Filter)是1970年由布隆提出的。它实际上是一个很长的二进制向量(位图)和一系列随机映射函数(哈希函数)
- 布隆过滤器可以用于检索一个元素是否在一个集合中。它的优点是空间效率和查询时间都远远超过一般的算法,缺点是有一定的误识别率和删除困难
- 将所有可能存在的数据哈希到一个足够大的bitmaps中,一个一定不存在的数据会被这个bitmaps拦截掉,从而避免了对底层存储系统的查询压力
- 进行实时监控:当发现Redis的命中率开始极速降低,需要排查访问对象和访问的数据,和运维人员配合,可以设置黑名单限制服务
边栏推荐
- Lengsuanling, a 30-year tortuous history of IPO of a domestic brand
- Test APK exception control netlocation attacker development
- vulnhub-The Planets: Earth
- Uni app custom navigation
- 轻便型FDW框架 for pb
- mixin--混入
- 利用阿里云国际购买的服务器搭建个人网站步骤
- 堆叠条形图鼠标移入tooltip中提示过滤为0元素,实现自定义气泡
- synergy: server refused client with our name
- canvas 高级功能(中)
猜你喜欢

LeetCode:497. Random points in non overlapping rectangles -- medium

连接mysql报错 errorCode 1129, state HY000, Host ‘xxx‘ is blocked because of many connection errors

Microsoft Word tutorial, how to change page orientation and add borders to pages in word?

AttributeError: module ‘collections‘ has no attribute ‘MutableMapping‘

分布式服务理论基础

面试必备——synchronized底层原理的基础知识

Deploying static websites using OSS and CDN on Alibaba cloud international

AttributeError: module ‘collections‘ has no attribute ‘MutableMapping‘

canvas 高级功能(中)
![[generation confrontation network learning part I] classic Gan and its existing problems and related improvements](/img/5a/0a4015cd4dcc21afd16ca7f895d909.png)
[generation confrontation network learning part I] classic Gan and its existing problems and related improvements
随机推荐
Uncover secrets: how can wechat red envelopes in the Spring Festival Gala resist 10billion requests?
中国工科研究生200多篇英文论文中最常见的习惯(The Most Common Habits from more than 200 English Papers written by Gradua)
Kcon 2022 topic public selection is hot! Don't miss the topic of "favorite"
Service management and communication, basic principle analysis
The most common habits from more than 200 English papers written by gradua
CET-6 - Business English - the last recitation before the test
What is the difference between localhost and 127.0.0.1?
LeetCode:497. 非重叠矩形中的随机点————中等
暗黑破坏神不朽WIKI地址 暗黑破坏神不朽数据库地址分享
knife4j配置使用直接拷贝即可
Pytorch deep learning -- neural network convolution layer conv2d
Li Kou 10821084 solution_ Question of SQL query type
Monitoring is easy to create a "quasi ecological" pattern and empower Xinchuang to "replace"
Jiangbolong forestee xp2000 PCIe 4.0 SSD multi encryption function, locking data security
Why do some web page style attributes need a colon ":" and some do not?
Tutoriel Microsoft Word "5", comment changer les marges de page et créer une barre de nouvelles en word?
Canvas advanced functions (Part 1)
pdf.js-----js解析pdf文件实现预览,并获取pdf文件中的内容(数组形式)
H5 van popup full screen pop-up window, simulates the page fallback effect, supports the return button in the upper left corner, and is suitable for physical return, side sliding and bottom return key
观点丨Play and Earn 会让加密游戏误入歧途