程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Redis教程 >> 關於Redis >> Redis的LRU機制介紹

Redis的LRU機制介紹

編輯:關於Redis

在Redis中,如果設置的maxmemory,那就要配置key的回收機制參數maxmemory-policy,默認volatile-lru,參閱Redis作者的原博客:antirez weblog >> Redis as an LRU cache

原文中寫得很清楚:
復制代碼 代碼如下:
Another way to use Redis as a cache is the maxmemory directive, a feature that allows specifying a maximum amount of memory to use. When new data is added to the server, and the memory limit was already reached, the server will remove some old data deleting a volatile key, that is, a key with an EXPIRE (a timeout) set, even if the key is still far from expiring automatically.

在Redis服務器占用內存達到maxmemory的情況下,當再想增加內存占用時,會按maxmemory-policy機制將老的數據刪除。這裡簡單說一下volatile-lru,Redis會按LRU算法刪除設置了過期時間但還沒有過期的key,而對於沒有設置過期時間的key,Redis是永遠保留的。當然,如果你不想刪除沒有過期的key,那可以使用noeviction機制
復制代碼 代碼如下:
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached? You can select among five behavior:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved