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 生日广州男生祝福语简短