Redis学习之数据淘汰机制

数据淘汰机制

为了防止内存溢出,可采取以下方法:

在redis中,允许用户设置最大使用内存大小
单台redis服务器,最大内存使用不应超过20G(建议)
maxmemory 512G

给key设置过期时间

给maxmemory-policy设置相应的数据淘汰策略

# LRU means Least Recently Used
    LRU意思是:最近最少使用。判断最近被使用的时间,目前最远的数据优先被淘汰
# LFU means Least Frequently Used
    LFU意思是:最不经常使用。在一段时间内,数据被使用次数最少的,优先被淘汰

# volatile-lru -> Evict using approximated LRU among the keys with an expire set.
                从已设置过期时间的数据集中挑选最近最少使用的数据淘汰    
# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
                从已设置过期时间的数据集中,删除一段时间内使用次数最少的数据
# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
                从已设置过期时间的数据集中挑选最近将要过期的数据淘汰
# volatile-random -> Remove a random key among the ones with an expire set.
                从已设置过期时间的数据集中,随机挑选数据淘汰
# allkeys-lru -> Evict any key using approximated LRU. ----------------------》 广泛采用的策略
                从数据集中挑选最近最少使用的数据淘汰
# allkeys-lfu -> Evict any key using approximated LFU.
                从数据集中,删除一段时间内使用次数最少的数据
# allkeys-random -> Remove a random key, any key.
                从数据集中随机挑选数据淘汰
# noeviction -> Don't evict anything, just return an error on write operations.
                禁止淘汰任何数据(默认配置),对于写操作,返回错误信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值