当前位置:网站首页>Redis 过期 key 清理删除策略汇总
Redis 过期 key 清理删除策略汇总
2022-04-23 09:30:00 【潘广宇 de 小白笔记】
Redis 底层使用了三种策略来清理过期的key
一、被动清理
触发条件:读/写一个已经过期的key
当读写一个key时,Redis首先检查key是否存在,若存在且已经过期,则删除key的同时返回nil给客户端
二、定期清理
触发条件:Redis定期检查
redis会定期执行清理过期key的任务,运行频率由redis.conf中的hz参数决定,取值范围1~500,默认是10,代表每秒运行10次。
清理过程如下:
1)遍历所有的db
2)从db中设置了过期时间的key的集合中随机检查20个key
3)删除检查中发现的所有过期key
4)如果检查结果中25%以上的key已过期,则继续重复执行步骤2-3,否则继续遍历下一个db
调大hz将会提高redis定期任务的执行频率,如果redis中包含很多过期key的话,可以考虑将这个值调大,但要注意同时也会增加CPU的压力,redis作者建议这个值不要超过100。
三、强制删除
触发条件:Redis 使用内存达到 maxmemory 的配置,然后根据 maxmemory-policy 来清理过期 key
具体的 maxmemory-policy 可以参考我之前的文章:Redis LRU 缓存回收机制_潘广宇 de 小白笔记的博客-CSDN博客
清理过程是阻塞的,直到清理出足够的内存空间才会停止
参考:
版权声明
本文为[潘广宇 de 小白笔记]所创,转载请带上原文链接,感谢
https://panguangyu.blog.csdn.net/article/details/124347862
边栏推荐
- Kettle experiment conversion case
- JS node operation, why learn node operation
- 小程序报错:Cannot read property 'currentTarget' of undefined
- node安装
- 3、 6 [Verilog HDL] gate level modeling of basic knowledge
- Exclusive thoughts and cases of JS
- Two declaration methods of functions of JS
- Cloud computing competition -- basic part of 2020 competition [task 3]
- kettle庖丁解牛第14篇之JSON输入
- Detailed explanation of delete, truncate and drop principles in MySQL database
猜你喜欢
To remember the composition ~ the pre order traversal of binary tree
Exclusive thoughts and cases of JS
Go language learning notes - exception handling | go language from scratch
112. 路径总和
Kettle experiment conversion case
Yyds dry goods inventory ubuntu18 0.4 install MySQL and solve error 1698: access denied for user ''root' '@' 'localhost' '
【SQL server速成之路】数据库的视图和游标
Node installation
A must see wechat applet development guide 1 - basic knowledge
108. Convert an ordered array into a binary search tree
随机推荐
《信息系统项目管理师总结》第八章 项目干系人管理
MySQL of database -- Fundamentals
Emuelec compilation summary
【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
Failed to download esp32 program, prompting timeout
What is monitoring intelligent playback and how to use intelligent playback to query video recording
Two ways for flutter providers to share data
高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
Group Backpack
Go language learning notes - language interface | go language from scratch
Kernel PWN learning (4) -- double fetch & 0ctf2018 baby
First principle mind map
Summary of wrong questions 1
Leetcode题库78. 子集(递归 c实现)
Exclusive thoughts and cases of JS
kettle庖丁解牛第14篇之JSON输入
Wechat applet catchtap = "todetail" event problem
kettle实验
[Luke V0] verification environment 2 - Verification Environment components
JS DOM learn three ways to create elements