ruby-on-rails - 如何优雅地处理 Rails 缓存失败? (redis缓存)

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

我在我的应用程序中使用 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' 

最佳答案

凯文,

好奇,您使用的是哪个 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 的源代码,我没有看到包含该修复程序。

关于ruby-on-rails - 如何优雅地处理 Rails 缓存失败? (redis缓存),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10758349/

相关文章:

ruby-on-rails - 如何向新的 simple_form 2.0.0.rc 添加额外的组件

ruby-on-rails - Rails3 : rewrite url_for for subdomain support, 如何扩展 Action 邮件程序以使用此类 url_for

ruby-on-rails - 使用 session 变量设置数据库连接

multithreading - CPU 什么时候可以忽略 LOCK 前缀并使用缓存一致性?

redis - Redis中的级联删除

Redis zrange 将值排序为整数

mysql - SQL 'IN' 和 'NOT IN' 在一起

api - Sails JS 与 Redis 缓存

ios - 不使用 RestKit 缓存特定请求

redis - 如何处理 Redis 客户端中的 read() 超时?