Ruby on Rails和Redis:未初始化的常量Redis :: Namespace

时间:2018-09-27 23:52:25

标签: ruby-on-rails ruby redis ruby-on-rails-5

我在弄乱路线,决定重新启动Rails服务器,最终遇到此错误。我在带有Rails服务器2.8.4的rails 5上使用ruby。我尝试运行捆绑更新,以查看是否可以解决该问题,然后重新启动计算机,然后重新启动Redis服务器。我还尝试将redis.rb文件重命名为test.rb,这样是否可能是其他堆栈溢出问题中所述的名称冲突

我的控制台终端出现​​错误:

/home/ubuntu/workspace/config/initializers/redis.rb:1:in `<top (required)>': uninitialized constant Redis::Namespace (NameError)
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:655:in `block in load_config_initializer'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/activesupport-5.1.6/lib/active_support/notifications.rb:168:in `instrument'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:654:in `load_config_initializer'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:611:in `each'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:611:in `block in <class:Engine>'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `instance_exec'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `run'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:59:in `block in run_initializers'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:48:in `each'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:48:in `tsort_each_child'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:415:in `call'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:415:in `each_strongly_connected_component_from'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `call'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
        from /usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:58:in `run_initializers'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/application.rb:353:in `initialize!'
        from /home/ubuntu/workspace/config/environment.rb:5:in `<top (required)>'
        from config.ru:3:in `require_relative'
        from config.ru:3:in `block in <main>'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:55:in `instance_eval'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:55:in `initialize'
        from config.ru:in `new'
        from config.ru:in `<main>'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:49:in `eval'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:49:in `new_from_string'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:40:in `parse_file'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/rack-2.0.5/lib/rack/server.rb:319:in `build_app_and_options_from_config'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/rack-2.0.5/lib/rack/server.rb:219:in `app'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:24:in `app'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/rack-2.0.5/lib/rack/server.rb:354:in `wrapped_app'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:80:in `log_to_stdout'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:42:in `start'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:135:in `block in perform'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `tap'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `perform'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/command/base.rb:63:in `perform'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/command.rb:44:in `invoke'
        from /usr/local/rvm/gems/ruby-2.4.0/gems/railties-5.1.6/lib/rails/commands.rb:16:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

宝石文件:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.6'
# Use sqlite3 as the database for Active Record
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'devise'
gem 'bootstrap'
gem 'jquery-rails'
gem 'webpacker', '~> 3.5'
gem 'stripe'
gem 'httparty'
#gem 'mongoid', github: 'mongoid/mongoid'
#gem 'mongoid', '~> 6.2.0'
#gem 'bson_ext'
gem 'rspec-rails', '~> 3.6'
gem 'database_cleaner', '~> 1.6', '>= 1.6.1'

#gem 'rails_admin', '~> 1.3'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'promise'
gem 'time_difference', '~> 0.7.0'
gem 'graphql-client'
# gem 'pg'
gem 'redis'
gem 'redis-namespace', group: :production
gem 'newrelic_rpm'
gem 'redis-rails'
gem 'redis-rack-cache'
gem 'informant-rails'

gem 'sidekiq'
#gem 'tzinfo-data'


group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'sqlite3'
end

group :production do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'pg'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'graphiql-rails', group: :development

这是我的redis.rb

$redis = Redis::Namespace.new("chronoci", :redis => Redis.new)

1 个答案:

答案 0 :(得分:0)

由于某种原因,, group: :production已添加到gem 'redis-namespace', group: :production中的Gemfile中。删除group :production对我来说解决了这个问题