使用rails缓存时使用rails处理redis maxmemory情况

当redis达到’maxmemory’状态时,它会让客户端读取,但不会写入。

这当然会导致致命的错误……有没有办法让Rails处理缓存读取或写入错误,所以如果缓存中出现不好的事情(可用性,读取,写入等),它将继续作为如果缓存被设置为“关闭”?

有一些不同的行为可以告诉redis在填满内存时要遵守。

# 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选项。

我不是专家,我没有这样做。 这只是我目前对redis和rails的理解。