Redis的LRU机制介绍
在Redis中,如果设置的maxmemory,那就要配置key的回收机制参数maxmemory-policy,默认volatile-lru,参阅Redis作者的原博客:antirezweblog>>RedisasanLRUcache
原文中写得很清楚:
AnotherwaytouseRedisasacacheisthemaxmemorydirective,afeaturethatallowsspecifyingamaximumamountofmemorytouse.Whennewdataisaddedtotheserver,andthememorylimitwasalreadyreached,theserverwillremovesomeolddatadeletingavolatilekey,thatis,akeywithanEXPIRE(atimeout)set,evenifthekeyisstillfarfromexpiringautomatically.
在Redis服务器占用内存达到maxmemory的情况下,当再想增加内存占用时,会按maxmemory-policy机制将老的数据删除。这里简单说一下volatile-lru,Redis会按LRU算法删除设置了过期时间但还没有过期的key,而对于没有设置过期时间的key,Redis是永远保留的。当然,如果你不想删除没有过期的key,那可以使用noeviction机制
#MAXMEMORYPOLICY:howRediswillselectwhattoremovewhenmaxmemory #isreached?Youcanselectamongfivebehavior: # #volatile-lru->removethekeywithanexpiresetusinganLRUalgorithm #allkeys-lru->removeanykeyaccordinglytotheLRUalgorithm #volatile-random->removearandomkeywithanexpireset #allkeys-random->removearandomkey,anykey #volatile-ttl->removethekeywiththenearestexpiretime(minorTTL) #noeviction->don'texpireatall,justreturnanerroronwriteoperations
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短