当前位置:网站首页>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
边栏推荐
- Creation of raid0 and RAID5 and Simulation of how RAID5 works
- LGB, XGB, cat, k-fold cross validation
- 机器学习(六)——贝叶斯分类器
- Buuctf [actf2020 freshman competition] include1
- JS prototype chain
- 三、6【Verilog HDL】基础知识之门级建模
- Image processing in opencv -- Introduction to contour + contour features
- Distributed message oriented middleware framework selection - Digital Architecture Design (7)
- Two methods of building Yum source warehouse locally
- Two declaration methods of functions of JS
猜你喜欢

Pre parsing of JS

Distributed message oriented middleware framework selection - Digital Architecture Design (7)

kettle庖丁解牛第14篇之JSON输入

Acquisition of DOM learning elements JS

Exclusive thoughts and cases of JS

三、6【Verilog HDL】基础知识之门级建模

#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''

Kettle experiment (III)

112. Path sum

Machine learning (VI) -- Bayesian classifier
随机推荐
Colorui solves the problem of blocking content in bottom navigation
[SQL Server fast track] view and cursor of database
nn. Explanation of module class
JSON input of Chapter 14 of kettle paoding jieniu
Single sign on SSO
[C language] document operation
Acquisition of DOM learning elements JS
Applet error: cannot read property'currenttarget'of undefined
Summary of wrong questions 1
JS case to find the maximum value, reverse the array, bubble sort
npm报错 :operation not permitted, mkdir ‘C: \Program Files \node js \node_ cache _ cacache’
Chapter VIII project stakeholder management of information system project manager summary
Where is int a = 1 stored
Program, process, thread; Memory structure diagram; Thread creation and startup; Common methods of thread
SQL used query statements
MySQL - Chapter 1 (data types in MySQL)
On array replication
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
Kettle experiment conversion case
How to protect open source projects from supply chain attacks - Security Design (1)