首页 > 系统服务 > 详细

有关redis做cache优化

时间:2019-07-02 19:43:46      阅读:108      评论:0      收藏:0      [点我收藏+]
公司redis一直是用来做cache缓存的,如果不对其做优化,默认淘汰机制,在内存使用达到上限后会出现各种命令报错。
官方如下描述
noeviction: return errors when the memory limit was reached and the client is trying to execute commands that could result in more memory to be used (most write commands, but DEL and a few more exceptions).
谷歌翻译
noeviction:当达到内存限制并且客户端尝试执行可能导致使用更多内存的命令时返回错误(大多数写命令,但DEL和一些例外)。

既然作为cache就需要做优化
在线修改
登陆
##***:6379>
CONFIG SET SAVE " " 关闭本地持久化
CONFIG SET maxmemory 10G 使用最大内存(结合实际内存资源)
CONFIG SET maxmemory-policy "allkeys-lru" 设置达到最大内存后的淘汰机制

官方对淘汰机制的描述。
allkeys-lru: evict keys by trying to remove the less recently used (LRU) keys first, in order to make space for the new data added.
谷歌翻译
allkeys-lru:首先尝试删除最近使用较少的(LRU)密钥来逐出密钥,以便为添加的新数据腾出空间。

在线修改会在重启后失效以下为配置文件永久添加设置
vim redis.conf

maxmemory 10G
maxmemory-policy allkeys-lru
save ""
注释以下选项
#save 900 1
#save 300 10
#save 60 10000

有关redis-cache其他的优化以及淘汰机制选择请参考官方
https://redis.io/topics/lru-cache

有关redis做cache优化

原文:https://blog.51cto.com/12102819/2416382

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!