面试题之redis的过期时间原理


1、消极方法:每次访问key时判断key是否已经过期;

2、积极方法;周期性的从设置了过期时间的key中选择一部分的key进行删除

  a、随机测试20个带有timeout信息的key

  b、如果超过25%的key被删除,则重复执行整个流程

以下是redis官网原文

Specifically this is what Redis does 10 times per second:

  1. Test 20 random keys from the set of keys with an associated expire.
  2. Delete all the keys found expired.
  3. If more than 25% of keys were expired, start again from step 1.

官网地址:https://redis.io/commands/expire

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM