我有Rails 3.1.3 app并尝试将gem“redis”插入其中。
我在gemfile中添加了以下gem:
gem“redis-store”
在这篇文章之后,我将以下代码添加到environment / 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)( 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 is不属于捆绑包。将其添加到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
请帮助!
答案 0 :(得分:9)
尝试
gem 'redis-store', '~> 1.0.0'
答案 1 :(得分:9)
仅供参考我...在我将所有以下内容添加到我的Gemfile之前,我遇到了类似的问题。我正在运行Rails 3.2.3。
gem 'redis'
gem 'redis-store'
gem 'redis-rails'
答案 2 :(得分:5)
这就是你所需要的:
gem 'redis-rails' # Will install several other redis-* gems
答案 3 :(得分:2)
我遇到了与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']
答案 4 :(得分:0)
我认为这就是你在评论中的意思,AntonAL - 这对我有用:
gem 'redis-rails', RAILS_VERSION # Where RAILS_VERSION matches the version of your rails gem
不能比那更简单:)