点击(此处)折叠或打开
-
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
-
# is reached. You can select among five behaviors:
-
#
-
# volatile-lru -> Evict using approximated LRU among the keys with an expire set. //在设置了过期时间的key中,使用近似的lru淘汰策略
-
# allkeys-lru -> Evict any key using approximated LRU. //所有的key均使用近似的lru淘汰策略
-
# volatile-lfu -> Evict using approximated LFU among the keys with an expire set. //在设置了过期时间的key中,使用lfu淘汰策略
-
# allkeys-lfu -> Evict any key using approximated LFU. //所有的key均使用lfu淘汰策略
-
# volatile-random -> Remove a random key among the ones with an expire set. //在设置了过期时间的key中,使用随机淘汰策略
-
# allkeys-random -> Remove a random key, any key. //所有的key均使用随机淘汰策略
-
# volatile-ttl -> Remove the key with the nearest expire time (minor TTL) //使用ttl淘汰策略
-
# noeviction -> Don't evict anything, just return an error on write operations . //不允许淘汰,在写操作发生,但内存不够时,将会返回错误
-
#
-
# LRU means Least Recently Used
-
# LFU means Least Frequently Used
-
#
-
# Both LRU, LFU and volatile-ttl are implemented using approximated
-
# randomized algorithms.
这里暂不讨论LFU,TTL淘汰算法和noeviction的情况,仅仅讨论lru所有场景下的,淘汰策略具体实现。(LFU和TTL将在下一篇文章中详细分析)。
LRU淘汰的场景:
1.主动淘汰。
1.1 通过定时任务serverCron定期的清理过期的key。
2.被动淘汰
2.1 每次写入key时,发现内存不够,调用activeExpireCycle释放一部分内存。
2.2 每次访问相关的key,如果发现key过期,直接释放掉该key相关的内存。
首先我们来分析LRU主动淘汰的场景:
serverCron每间隔1000/hz ms会调用databasesCron方法来检测并淘汰过期的key。 (编辑:淮北站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|