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 送给学长毕业祝福语简短