面試題之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