找不到redis_store的缓存存储适配器

Ant*_*nAL 13 redis ruby-on-rails-3

我有Rails 3.1.3应用程序并尝试将gem"redis"插入其中.

我在gemfile中添加了以下gem:

宝石"redis-store"

在本文之后,我将以下代码添加到environment/development.rb:

config.gem "redis-store", :lib => "redis-store"
require "redis-store" # HACK
config.cache_store = :redis_store
Run Code Online (Sandbox Code Playgroud)

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

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

我已经弄清楚了,包括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.(宝石:: LoadError)

保持他们两个......

gem 'redis-store'
gem 'redis-rails'
Run Code Online (Sandbox Code Playgroud)

...给出了另一个错误

…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
Run Code Online (Sandbox Code Playgroud)

请帮忙!

小智 9

尝试

gem 'redis-store', '~> 1.0.0'
Run Code Online (Sandbox Code Playgroud)


小智 9

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

    gem 'redis'
    gem 'redis-store'
    gem 'redis-rails'
Run Code Online (Sandbox Code Playgroud)

  • 我在Rails 3.2.3中遇到了类似的问题.我用'gem'redis-rails'替换了'gem'redis-store'`,一切都还可以. (9认同)
  • 这是多余的-`redis-rails`包括其他两个gem作为依赖项 (2认同)

Yar*_*rin 7

这就是你所需要的:

gem 'redis-rails' # Will install several other redis-* gems
Run Code Online (Sandbox Code Playgroud)

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


小智 5

我在 Rails 5.2 应用程序中遇到了类似的问题。

原来问题出在production.rb. Rails guides 指示使用config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] },但这是不正确的。

什么对我有用:

在 Gemfile 中

gem 'redis-rails', '~> 5'
Run Code Online (Sandbox Code Playgroud)

config/environments/production.rb

config.cache_store = :redis_store, ENV['REDIS_URL']
Run Code Online (Sandbox Code Playgroud)