【问题标题】:Could not find cache store adapter for redis_store找不到 redis_store 的缓存存储适配器
【发布时间】:2012-04-04 04:42:47
【问题描述】:

我有 Rails 3.1.3 应用程序并尝试将 gem "redis" 插入它。

我已将以下 gem 添加到 Gemfile:

gem "redis-store"

在这篇文章之后,我在environments/development.rb中添加了以下代码:

config.gem "redis-store", :lib => "redis-store"
require "redis-store" # HACK
config.cache_store = :redis_store

应用无法启动,向 cache_store 抱怨:

/gems/activesupport-3.1.3/lib/active_support/cache.rb:65:in `lookup_store': 找不到 redis_store 的缓存存储适配器(没有要加载的文件——active_support/cache/redis_store)(运行时错误)。

我已经想通了,包括 gem "redis-rails" 而不是 "redis-store",但我遇到了另一个错误:

/Users/AntonAL/.rvm/gems/ree-1.8.7-2011.03@global/gems/bundler-1.0.21/lib/bundler/rubygems_integration.rb:143:in `gem': redis-store 是不是捆绑包的一部分。将其添加到 Gemfile。 (Gem::LoadError)

两者兼得……

gem 'redis-store'
gem 'redis-rails'

...给出另一个错误

…gems/redis-rails-0.0.0/lib/redis-rails/version.rb:1: Redis is not a module (TypeError)
    from …/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from …/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from …/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
    from …/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from …/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
    from …/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
    from …/gems/redis-rails-0.0.0/lib/redis-rails.rb:1
    from …/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    from …/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    from …/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
    from …/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `require'
    from …/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
    from …/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
    from …/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
    from …/config/application.rb:11
    from …/gems/railties-3.1.3/lib/rails/commands.rb:52:in `require'
    from …/gems/railties-3.1.3/lib/rails/commands.rb:52
    from …/gems/railties-3.1.3/lib/rails/commands.rb:49:in `tap'
    from …/gems/railties-3.1.3/lib/rails/commands.rb:49
    from script/rails:6:in `require'
    from script/rails:6

请帮忙!

【问题讨论】:

    标签: ruby-on-rails-3 redis


    【解决方案1】:

    试试

    gem 'redis-store', '~> 1.0.0'
    

    【讨论】:

    • 谢谢,最近我也找到了解决办法。我可以指定与我的 rails 环境版本匹配的“redis-store”版本。
    • Blam!谢谢一吨百万兰特
    【解决方案2】:

    仅供参考...在将以下所有内容添加到我的 Gemfile 之前,我遇到了类似的问题。我正在运行 Rails 3.2.3。

        gem 'redis'
        gem 'redis-store'
        gem 'redis-rails'
    

    【讨论】:

    • 我在 Rails 3.2.3 中遇到了类似的问题。我用gem 'redis-rails' 替换了gem 'redis-store',一切正常。
    • 这是多余的 - redis-rails 包含其他两个 gem 作为依赖项
    【解决方案3】:

    这就是你所需要的:

    gem 'redis-rails' # Will install several other redis-* gems
    

    (参见:https://github.com/redis-store/redis-rails)

    【讨论】:

      【解决方案4】:

      我在使用 Rails 5.2 应用时遇到了类似的问题。

      原来问题出在production.rb 中缓存存储的配置上。 Rails 指南表明使用config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] },但这是不正确的。

      什么对我有用:

      在 Gemfile 中

      gem 'redis-rails', '~> 5'
      

      在config/environments/production.rb

      config.cache_store = :redis_store, ENV['REDIS_URL']
      

      【讨论】:

      • 好电话。 Rails 网站上的文档是完全错误的。
      • 如果有人因为 Rails 5.2 而出现在这里,请查看文档,其中说明您应该安装基本的 redis 库,甚至更好的是,连接的hiredis 实现。 edgeguides.rubyonrails.org/…
      【解决方案5】:

      我认为这就是你在评论中的意思,AntonAL - 这对我有用:

      gem 'redis-rails', RAILS_VERSION # Where RAILS_VERSION matches the version of your rails gem
      

      没有比这更简单的了:)

      【讨论】:

      • 这些版本恰好同步是巧合。绝对不是使用 Gemfile 的可取方式。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      • 2019-03-24
      • 1970-01-01
      • 2021-08-25
      • 1970-01-01
      相关资源
      最近更新 更多