Redis 内存驱逐策略

1 缓存替代算法

cache algorithms (also frequently called cache replacement algorithms or cache replacement policies).
When the cache is full, the algorithm must choose which items to discard to make room for the new ones.
当缓存已满时, 缓存替代算法必须要选择要丢弃的数据项, 以便为新的数据项腾出空间.
wiki 上有很多 缓存替代算法 的实现, 参考这里.

2 Redis 内存驱逐策略(Eviction policies)

以下内容翻译自 Redis 官网的 Eviction policies 介绍.

驱逐策略定义了 在数据库超出内存限制时, Redis 所采用的处理方法.

驱逐策略有:

PolicyDescription
noeviction Returns an error if the memory limit has been reached when trying to insert more data(内存使用超过限制时, 插入新的数据返回会报错)
allkeys-lruEvicts the Least Recently Used keys out of all keys(对所有 key 进行驱逐, 删除 最近最少使用 的key)
allkeys-lfuEvicts the Least Frequently Used keys out of all keys(对所有 key 进行驱逐, 删除 最不常使用 的key)
allkeys-randomRandomly evicts keys out of all keys(对所有 key 进行驱逐, 随机删除key)
volatile-lruEvicts the Least Recently Used keys out of all keys with an “expire” field set(对设置了过期时间的 key 进行驱逐, 删除 最近最少使用 的key)
volatile-lfuEvicts the Least Frequently Used keys out of all keys with an “expire” field set(对设置了过期时间的 key 进行驱逐, 删除 最不常使用 的key)
volatile-randomRandomly evicts keys with an “expire” field set(对设置了过期时间的 key 进行驱逐, 随机删除key)
volatile-ttlEvicts the shortest time-to-live keys out of all keys with an “expire” field set.(对设置了过期时间的 key 进行驱逐, 删除存活时间最短的key, 越早过期的key越优先被删除)

其中, volatile-lru 是默认的驱逐策略.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值