当前位置:网站首页>Redis网红高频面试题三连:缓存穿透?缓存击穿?缓存雪崩?
Redis网红高频面试题三连:缓存穿透?缓存击穿?缓存雪崩?
2022-07-27 16:04:00 【InfoQ】
Redis网红面试题三连
面试题1:怎么解决缓存穿透问题的?
- 缓存容量有限,不可能去缓存所有数据,查询到未被缓存的数据就会发生穿透是正常情况。
- 互联网业务的数据访问模型一般是遵循二八原则的,即 20% 的数据为热点数据,80% 的数据是非热点不被常访问的数据。既然缓存容量有限,且20%的数据为热点数据,那我们可以利用有限的容量去缓存那 20% 的数据来保护我们的系统,至于80%非热点不常用的数据发生穿透就穿透了,数据库吃得住。
- 接口参数校验:
- 设置空值:
- 布隆过滤器:


- 经过K个哈希函数计算该数据,返回K个计算出的hash值
- 这些K个hash值映射到对应的K个二进制的数组下标
- 将K个下标对应的二进制数据改为1。
- 经过K个哈希函数计算该数据,对应计算出的K个hash值
- 经过hash值找到对应的二进制的数组下标
- 如果存在其中一处位置的二进制数据是0,那么该数据不存在。若是都是1,该数据存在集合中(但由于存在Hash碰撞,判断数据存在时可能存在误判)。
- 因为存储的是二进制数据,因此占用的空间很小;
- 它的插入和查询速度是很是快的,时间复杂度是O(K),能够联想一下HashMap的过程;
- 保密性很好,由于自己不存储任何原始数据,只有二进制数据
- 存在误判

- 删除困难
面试题2:说一下缓存击穿吧,你们是怎么解决的?
static Lock reenLock = new ReentrantLock(); public List<String> getData04() throws InterruptedException { List<String> result = new ArrayList<String>(); // 从缓存读取数据 result = getDataFromCache(); if (result.isEmpty()) { if (reenLock.tryLock()) { try { System.out.println("拿到锁了,从DB获取数据库后写入缓存"); // 从数据库查询数据 result = getDataFromDB(); // 将查询到的数据写入缓存 setDataToCache(result); } finally { reenLock.unlock();// 释放锁 } } else { result = getDataFromCache();// 先查一下缓存 if (result.isEmpty()) { System.out.println("我没拿到锁,缓存也没数据,先小憩一下"); Thread.sleep(100);// 小憩一会儿 return getData04();// 重试 } } } return result; }面试题3:那缓存雪崩说说你们是怎么解决的?
边栏推荐
- hutool- 数字计算
- hutool 字符串工具类
- 图形界面编程
- Bug records using distributed framework WCF
- golang 等待一组goroutine完成,并带返回值(2)
- Knowledge dry goods: basic storage service novice Experience Camp
- [user article] examples of P4 consolidation practice guide disassemble resolve
- 解决Reids不能被其他IP访问
- 用slmgr命令激活正版Win7旗舰版系统
- 注释中的{@code}、{@Link} 与<p>等标签
猜你喜欢

Machine learning: IOU of concept understanding

Introduction to ef framework

Know things by learning | build a real-time anti plug-in mechanism from 0 to 1 to supplement the offensive and defensive power of mobile games in multiple dimensions

浅论分布式训练中的recompute机制

知物由学 | 再造巴别塔,我们如何进行NLP跨语言知识迁移?

类的六大关系——依赖和关联的区别
![[Southwest University] information sharing of postgraduate entrance examination and re examination](/img/15/298ea6f7367741e1e085007c498e51.jpg)
[Southwest University] information sharing of postgraduate entrance examination and re examination

2022 safety officer-a certificate examination questions and online simulation examination

Localization within Communities

The Ministry of industry and information technology re governs data security, and Netease Yidun "privacy compliance" keeps the bottom line of enterprise operation
随机推荐
【Codeforces】 A. Computer Game
使用分布式框架WCF出现的BUG记录
Learn from what you know | Yidun self-developed text real-time clustering technology, and wipe out the same kind of harmful content in social networks
[learning notes] Lombok's @builder annotation
[learning notes] the implementation principle of the ordered set Zset in redis - skip table
GIS数据漫谈(五)— 地理坐标系统
类的六大关系——依赖和关联的区别
[user article] examples of P4 consolidation practice guide disassemble resolve
[learning notes] classification of locks in the database
国巨斥资18亿美元收购竞争对手Kemet,交易或在明年下半年完成
Find redundant duplicate records in the table, delete and retain the minimum one
Golang worker pool
Golang Chan implements mutual exclusion
备份表恢复表
Big gap? Requirements and conditions for candidates with different academic qualifications to take the postgraduate entrance examination
[learning notes] advanced version of MySQL database - index optimization, slow query, locking mechanism, etc
MySQL solves the problem of insert failure caused by duplicate unique indexes
What every Salesforce developer should know about Dates and Times in Apex
Activate genuine win7 ultimate system with slmgr command
[learning notes] solutions to hot account problems