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
热门推荐
10 治愈语句祝福语大全简短
11 生日留言简短祝福语大全
12 生日祝福语贺卡文字简短
13 买房的祝福语高级简短
14 老年 生日祝福语大全简短
15 关于老师蛋糕祝福语简短
16 元宵贺卡祝福语结婚简短
17 师姐毕业送花祝福语简短
18 同事除夕加班祝福语简短