Redis的LRU機制介紹
在Redis中,如果設(shè)置的maxmemory,那就要配置key的回收機制參數(shù)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服務(wù)器占用內(nèi)存達到maxmemory的情況下,當再想增加內(nèi)存占用時,會按maxmemory-policy機制將老的數(shù)據(jù)刪除。這里簡單說一下volatile-lru,Redis會按LRU算法刪除設(shè)置了過期時間但還沒有過期的key,而對于沒有設(shè)置過期時間的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
相關(guān)文章
Redis集群的三種部署方式及三種應(yīng)用問題的處理
這篇文章主要介紹了Redis集群的三種部署方式及三種應(yīng)用問題的處理,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-04-04
Redis實現(xiàn)分布式Session管理的機制詳解
這篇文章主要介紹了Redis實現(xiàn)分布式Session管理的機制詳解,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01
windows環(huán)境下Redis+Spring緩存實例講解
這篇文章主要為大家詳細介紹了windows環(huán)境下Redis+Spring緩存實例教程,感興趣的小伙伴們可以參考一下2016-04-04
Redis面試必備之緩存設(shè)計規(guī)范與性能優(yōu)化詳解
你是否在使用Redis時,不清楚Redis應(yīng)該遵循的設(shè)計規(guī)范而苦惱,你是否在Redis出現(xiàn)性能問題時,不知道該如何優(yōu)化而發(fā)愁,快跟隨小編一起學(xué)習(xí)起來吧2024-03-03
Redis高效率原因及數(shù)據(jù)結(jié)構(gòu)分析
這篇文章主要為大家詳細的介紹了Redis高效的原因以及分析了Redis高效的數(shù)據(jù)結(jié)構(gòu),有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-09-09
nestjs使用redis實現(xiàn)ip限流的步驟詳解
如果使用nestjs開發(fā)接口并部署之后,我們通常需要考慮到接口是否會被惡意盜刷消耗過多的資源,一個簡單的方式就是限制在單位時間內(nèi)的訪問次數(shù),所以本文給大家介紹了nestjs使用redis實現(xiàn)ip限流的步驟,需要的朋友可以參考下2025-01-01
redis連接報錯error:NOAUTH Authentication required
本文主要介紹了redis連接報錯error:NOAUTH Authentication required,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
關(guān)于Redis最常見的十道面試題總結(jié)大全
Redis作為一個高性能的內(nèi)存數(shù)據(jù)存儲系統(tǒng),具有快速讀寫、持久性、數(shù)據(jù)結(jié)構(gòu)多樣性等特點,廣泛應(yīng)用于各種應(yīng)用場景,這篇文章主要給大家介紹了關(guān)于Redis最常見的十道面試題總結(jié)的相關(guān)資料,需要的朋友可以參考下2024-07-07

