2

我在安装了 Apache 的 Ubuntu 服务器上使用乘客。

当我尝试在其上加载带有 redis 的 ruby​​ 应用程序时,我收到此错误。

Error message:
    uninitialized constant Redis::Client::ALIASES

Exception class:
    NameError

Application root:
    /xxx/ruby 



0   /usr/local/rvm/gems/ruby-1.9.3-p194/gems/redis-namespace-0.4.3/lib/redis/namespace.rb   128     in `'
1   /usr/local/rvm/gems/ruby-1.9.3-p194/gems/redis-namespace-0.4.3/lib/redis/namespace.rb   4   in `'
2   /usr/local/rvm/gems/ruby-1.9.3-p194/gems/redis-namespace-0.4.3/lib/redis/namespace.rb   3   in `'
3   /usr/local/rvm/gems/ruby-1.9.3-p194/gems/resque-1.8.2/lib/resque.rb     1   in `'
4   /usr/local/rvm/gems/ruby-1.9.3-p194/gems/resque-1.8.2/lib/resque/server.rb  3   in `'
5   /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb    68  in `require'
6   /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb    68  in `block (2 levels) in require'
7   /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb    66  in `each'
8   /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb    66  in `block in require'
9   /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb    55  in `each'
10  /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb    55  in `require'
11  /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler.rb    119     in `require'
12  /xxx/ruby/config/application.rb     7   in `'
13  /xxx/ruby/config/environment.rb     4   in `require'
14  /xxx/ruby/config/environment.rb     4   in `'
15  config.ru   3   in `require'
16  config.ru   3   in `block in '
17  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb     51  in `instance_eval'
18  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb     51  in `initialize'
19  config.ru   1   in `new'
20  config.ru   1   in `'/usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb    225     in `eval'
21  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb     225     in `load_rack_app'
22  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb     157     in `block in initialize_server'
23  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/utils.rb    572     in `report_app_init_status'
24  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb     154     in `initialize_server'
25  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb  204     in `start_synchronously'
26  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb  180     in `start'
27  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb     129     in `start'
28  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb    253     in `block (2 levels) in spawn_rack_application'
29  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server_collection.rb   132     in `lookup_or_add'
30  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb    246     in `block in spawn_rack_application'
31  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server_collection.rb   82  in `block in synchronize'
32  < td=""> <> prelude>    10:in `synchronize'
33  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server_collection.rb   79  in `synchronize'
34  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb    244     in `spawn_rack_application'
35  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb    137     in `spawn_application'
36  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb    275     in `handle_spawn_application'
37  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb  357     in `server_main_loop'
38  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb  206     in `start_synchronously'
39  /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/helper-scripts/passenger-spawn-server     99  in `'

这就是我的 config.ru 的样子。

# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment',  __FILE__)
run Rack::URLMap.new \
  "/" => xxx::Application,
  "/resque" => Resque::Server.new

这就是我的 resque_r.rb 的样子(它位于 config/initializers 中)。

require "rubygems"
require 'resque_scheduler'

Resque.redis = 'localhost:6379'
Resque.redis.namespace = "resque:SchedulerExample"

# If you want to be able to dynamically change the schedule,
# uncomment this line.  A dynamic schedule can be updated via the
# Resque::Scheduler.set_schedule (and remove_schedule) methods.
# When dynamic is set to true, the scheduler process looks for
# schedule changes and applies them on the fly.
# Note: This feature is only available in >=2.0.0.
Resque::Scheduler.dynamic = true

Dir["#{Rails.root}/app/workers/*.rb"].each { |file| require file }

# The schedule doesn't need to be stored in a YAML, it just needs to
# be a hash.  YAML is usually the easiest.
Resque.schedule = YAML.load_file(Rails.root.join('config', 'resque_schedule.yml'))

我的宝石文件

source 'https://rubygems.org'

gem 'rails', '3.2.3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do

  gem 'sass-rails', :require => 'sass'

  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby

  gem 'uglifier', '>= 1.0.3'

  gem 'compass-rails'

end

gem 'twitter-bootstrap-rails', "~> 2.0rc0"

gem 'jquery-rails'

gem 'feedzirra'

gem "friendly_id", "~> 4.0.1"

gem 'acts-as-taggable-on', '~> 2.2.2'

gem 'will_paginate', '~> 3.0'

gem 'gon'

gem 'wikitext'

gem 'twitter'

gem 'yaml_db'

#JSON PARSER
gem "oj", "~> 1.2.8"

gem "mysql2", "~> 0.3.11"

gem 'resque', :require => "resque/server"

gem 'resque-scheduler', :require => 'resque_scheduler'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
4

4 回答 4

1

从您的堆栈跟踪来看,它看起来像是在加载时发生错误config.ru

看起来您没有包含resque/server在 config.ru 文件中。

这是我在我的一个项目中使用的配置:

require ::File.expand_path('../config/environment',  __FILE__)
require 'resque/server'

run Rack::URLMap.new \
  "/"       => DmWorkflow::Application,
  "/resque" => Resque::Server.new

另外,我不知道它是否对您有影响,但我将这些包括在我的Gemfile喜欢中:

gem 'resque'
gem 'resque-loner' 
gem 'resque-scheduler', ">= 2.0.0.h"
于 2012-05-24T10:36:15.137 回答
1

You're running old version of resque gem. New version of resque depends on redis-namespace version 1.0.2 and upper, but your stack trace says that it loads redis-namespace v0.4.3.

Try running bundle update. If the versions still not right, add to your Gemfile:

gem 'redis-namespace', '~> 1.0.2'

Alternatively you can install edge version of resque via git:

gem 'resque', github: 'defunkt/resque'
于 2012-05-24T10:58:38.247 回答
1

我不太明白你做了什么来解决这个问题,因为我相信它实际上是 redis-namespace 中的一个错误。请参阅问题 #38

于 2012-05-24T13:08:56.063 回答
0

我在服务器上安装了错误版本的 redis。我没有使用 apt-get install redis-server 我手动安装了 redis-server 并解决了问题!

于 2012-05-24T11:51:36.367 回答