redis内存策略

    redis设置配置文件的maxmemory参数,可以控制其最大可用内存大小(字节),如果内存超过了,没有设置内存策略,则程序报错。需要设置内存策略。

配置文件中的maxmemory-policy:其默认值是noeviction。

  

LRU算法最近最少使用算法默认删除最近最少使用的键。同时,我们需要注意一下redis中并不会准确的删除所有键中最近最少使用的键,而是随机抽取3个键,删除这三个键中最近最少使用的键.并且这三个数字是可以配置。位置在配置文件中:maxmeory-samples

################################### LIMITS ####################################

#最大客户端连接数量
# maxclients 10000


# maxmemory <bytes>
#最大内存
maxmemory 473000000

# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations

#设置内存策略
maxmemory-policy volatile-lru

#  and minimal TTL algorithms are not precise algorithms but approximated
#LRU 随机删除key的数量
maxmemory-samples 5

############################## APPEND ONLY MODE ###############################
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值