码迷,mamicode.com
首页 > 系统相关 > 详细

有关redis做cache优化

时间:2019-07-02 21:08:14      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:use   recent   执行   返回   修改   缓存   exce   cut   save   

公司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优化

标签:use   recent   执行   返回   修改   缓存   exce   cut   save   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!