Redis的LRU機制介紹_Redis

來源:互聯網
上載者:User

在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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.