使用Rails缓存时使用Rails处理Redis最大内存情况 [英] handling redis maxmemory situations with rails when using rails caching

查看:59
本文介绍了使用Rails缓存时使用Rails处理Redis最大内存情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当redis达到最大内存"条件时,它将允许客户端进行读取,但不能进行写入.

When redis hits a 'maxmemory' condition, it will let the client do a read, but not a write.

这当然会导致致命错误……有什么方法可以使Rails处理缓存的读或写错误,因此,如果缓存发生故障(可用性,读取,写入等),它将继续好像缓存设置为"off"一样运行?

This results in a fatal error of course... is there any way to make Rails handle a cache read OR write error, so if something bad happens to the cache (availability, read, write, etc), it will continue to run as if if caching was set to "off"?

推荐答案

您可以告诉Redis在内存已满时要遵守的不同行为.

There are different behaviours that you can tell redis to abide by when it has filled up its memory.

# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly 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

也许最好的选择是'volatile-ttl',并确保所有缓存都包括:expires_in选项.

Maybe the best options is 'volatile-ttl', and make sure that all your caches include the :expires_in options.

我不是专家,也没有这样做.这只是基于我目前对Redis和Rails的理解.

I'm no expert and I have not done this. This is just base on my current understanding of redis and rails.

这篇关于使用Rails缓存时使用Rails处理Redis最大内存情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆