当前位置:网站首页>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
边栏推荐
- DVWA range practice
- Kernel PWN learning (4) -- double fetch & 0ctf2018 baby
- ALV树(LL LR RL RR)插入删除
- Write down the post order traversal of the ~ binary tree
- I don't understand time, timestamp and time zone. Look at this article
- 重载、重写、隐藏的对比
- Flink 流批一体在小米的实践
- 员工试用期转正申请书(泸州老窖)
- Go language learning notes - array | go language from scratch
- Sql1 [geek challenge 2019]
猜你喜欢
Personal homepage software fenrus
AQS & reentrantlock implementation principle
Kernel PWN learning (3) -- ret2user & kernel ROP & qwb2018 core
Sql1 [geek challenge 2019]
Kettle experiment (III)
Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
Yyds dry goods inventory ubuntu18 0.4 install MySQL and solve error 1698: access denied for user ''root' '@' 'localhost' '
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
三、6【Verilog HDL】基础知识之门级建模
501. Mode in binary search tree
随机推荐
Detailed explanation of delete, truncate and drop principles in MySQL database
Acquisition of DOM learning elements JS
Kettle experiment
653. Sum of two IV - input BST
基于ThinkPHP5版本TRC20-资金归集解决方案
Machine learning (VI) -- Bayesian classifier
Kettle experiment conversion case
SQL used query statements
web页面如何渲染
kernel-pwn学习(3)--ret2user&&kernel ROP&&QWB2018-core
JS scope, scope chain, global variables and local variables
Colorui solves the problem of blocking content in bottom navigation
搞不懂时间、时间戳、时区,快来看这篇
Principle of synchronized implementation
Two methods of building Yum source warehouse locally
108. 将有序数组转换为二叉搜索树
Exclusive thoughts and cases of JS
Number theory to find the sum of factors of a ^ B (A and B are 1e12 levels)
考研线性代数常见概念、问题总结
Three ways to create objects in JS