当前位置:网站首页>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的命中率开始极速降低,需要排查访问对象和访问的数据,和运维人员配合,可以设置黑名单限制服务
边栏推荐
- LeetCode:1037. 有效的回旋镖————简单
- 揭秘:春晚微信红包,是如何抗住 100 亿次请求的?
- Unity analyzes the rendering of built-in terrain and does some interesting things
- How to use Diablo immortal database
- 电子招标采购商城系统:优化传统采购业务,提速企业数字化升级
- The new audio infinix machine appears in the Google product library, and Tecno CaMon 19 is pre installed with Android 13
- Microsoft Word tutorial "5", how to change the margins and create a newsletter column in word?
- knife4j配置使用直接拷贝即可
- mixin--混入
- [computer use] how to set software startup without auto startup
猜你喜欢

Software definition boundary (SDP)

pdf.js-----js解析pdf文件实现预览,并获取pdf文件中的内容(数组形式)

JD released ted-q, a large-scale and distributed quantum machine learning platform based on tensor network acceleration

解决idea超过5个相同包的时候自动变成*的问题

35岁被裁员,还能拥有美妙人生吗?

Microsoft Word tutorial "5", how to change the margins and create a newsletter column in word?

pdf.js-----js解析pdf文件實現預覽,並獲取pdf文件中的內容(數組形式)

自定义日期组件,左右按钮控制向前或向后翻年、翻月、翻周、翻日

Canvas advanced functions (Part 1)

A small case with 666 times performance improvement illustrates the importance of using indexes correctly in tidb
随机推荐
JS basic and frequently asked interview questions [] = =! [] result is true, [] = = [] result is false detailed explanation
魔塔类游戏实现源码及关卡生成
mysql基础篇之mysql在已有表中添加自动增加的主键(或任意一个字段)
农产品期货开户的条件是什么?现在开户的手续费是多少?
轻便型FDW框架 for pb
20192407 2021-2022-2 experimental report on Experiment 8 of network and system attack and Defense Technology
Four methods to obtain the position index of the first n values of the maximum and minimum values in the list
Quick start to elastic job, three minutes to experience distributed scheduled tasks
Self attention and multi head attention
RuntimeError: Attempting to deserialize object on CUDA device 1 but torch. cuda. device_ count() is 1.
Arduino中Serial.print()与Serial.write()函数的区别,以及串口通信中十六进制与字符串的收发格式问题和转换过程详解
暗黑破坏神不朽数据库怎么用 暗黑破坏神手游不朽数据库使用方法
LeetCode:1037. Effective boomerang - simple
Monitoring is easy to create a "quasi ecological" pattern and empower Xinchuang to "replace"
[technical fragment] implementation of renaming and filtering duplicate name files with suffixes
knife4j配置使用直接拷贝即可
Deploying static websites using OSS and CDN on Alibaba cloud international
redis设置密码命令(临时密码)
Steps to build a personal website using servers purchased by Alibaba cloud international
Test APK exception control netlocation attacker development