【问题标题】:How to gracefully handle Rails cache failure? (redis-cache)如何优雅地处理 Rails 缓存失败? (redis缓存)
【发布时间】:2012-06-01 06:26:28
【问题描述】:

我在我的应用程序中使用 redis-cache 进行片段缓存。当 redis 关闭或无法访问时,我会收到引发 500 错误的超时异常。

这种情况很少发生,但对于缓存,我希望 rails 将超时视为:

  • 写入时无操作
  • 读取时缓存未命中。

有什么建议吗?这是在 Rails 缓存中可配置的东西,还是我需要做一些猴子补丁来优雅地处理这种情况?

我的堆栈跟踪的相关部分如下,以防它有任何帮助。 . .

execution expired /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/timeout.rb:60:in `new' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/connection/ruby.rb:26:in `connect' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/connection/ruby.rb:128:in `with_timeout' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/connection/ruby.rb:25:in `connect' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/client.rb:227:in `establish_connection' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/client.rb:23:in `connect' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/client.rb:247:in `ensure_connected' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/client.rb:137:in `process' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/client.rb:206:in `logging' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/client.rb:136:in `process' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis/client.rb:46:in `call' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis.rb:157:in `get' /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/monitor.rb:242:in `synchronize' bundle/gems/ruby/1.8/gems/redis-2.2.2/lib/redis.rb:156:in `get' bundle/gems/ruby/1.8/gems/redis-store-1.0.0.1/lib/redis/store/interface.rb:5:in `get' bundle/gems/ruby/1.8/gems/redis-store-1.0.0.1/lib/redis/store/marshalling.rb:13:in `get' bundle/gems/ruby/1.8/gems/redis-store-1.0.0.1/lib/active_support/cache/redis_store.rb:119:in `read_entry'

【问题讨论】:

    标签: ruby-on-rails caching redis redis-cache


    【解决方案1】:

    凯文,

    好奇,你用的是什么版本的 Rails?

    redis-store 项目上的这个问题似乎与您遇到的问题有关:https://github.com/jodosha/redis-store/issues/56。不过,该修复仅针对 Rails 3。

    Rails 2 的修复在这里:https://github.com/jodosha/redis-store/pull/83。查看 redis-store 1.0.0.1 的源代码,我没有看到包含该修复程序。

    【讨论】:

    • 感谢 Carlos - 我们在 Rails 3 上。该修复处理拒绝连接,但不处理超时。
    猜你喜欢
    • 2015-02-26
    • 2015-02-19
    • 2013-12-31
    • 2020-01-07
    • 2019-10-02
    • 2019-06-18
    • 1970-01-01
    • 2016-08-28
    • 2013-09-26
    相关资源
    最近更新 更多