2

I'm using passenger on Ubuntu Server with Apache installed.

When I try to load the ruby application with redis on it I get this error.

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 `'

This is how my config.ru looks like.

# 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

This is how my resque_r.rb looks like (its located in 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'))

My Gem file

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'
Philip
  • 6,827
  • 13
  • 75
  • 104

4 Answers4

1

From your stack trace it looks like the error occurs when it's loading config.ru.

It looks like you didn't include resque/server in your config.ru file.

Here's the configuration I use on one of my projects:

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

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

Also, I don't know if it makes a difference for you, but I include these in my Gemfile like this:

gem 'resque'
gem 'resque-loner' 
gem 'resque-scheduler', ">= 2.0.0.h"
Kevin Bedell
  • 13,254
  • 10
  • 78
  • 114
  • Do you have them on Ubuntu with Apache? It didn't help me, It works for me localy but not on the server. – Philip May 24 '12 at 10:44
  • I'm deploying on heroku. Did you run `bundle install` on the server? – Kevin Bedell May 24 '12 at 10:45
  • I've tried to change to those settings you have in your gemfile, and it install redis 2.2.2 (instead of 3.0) and uses that. But then it gives me another error. The same as this person http://stackoverflow.com/questions/3696932/runtimeerror-err-unknown-command-running-redis-gem-on-ruby And from what I can tell it complains that the versions of my redis server is to old; I will update it and see if it gives me any errors. Get back to you asap! – Philip May 24 '12 at 11:01
  • Interesting... My `Gemfile.lock` shows `redis (2.2.2)` as well. But it all works great. According to rubygems.org, `redis (3.0.0)` was just released yesterday. That may be part of your issue. – Kevin Bedell May 24 '12 at 11:07
  • Actually, I used sudo-apt get install redis-server which installed a old v. of redis, that was a big misstake, i uninstalled and reinstalled redis manually and that solved the problem! :) – Philip May 24 '12 at 11:50
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'
NARKOZ
  • 27,203
  • 7
  • 68
  • 90
  • The main problem was that I was on the wrong version of redis. I used sudo apt-get install redis-server which installed a old v. of redis. I uninstalled that and installed redis manually, and that solved the problem I had. But I did update my gemfile with namespace 1.0.2, Thanks for the info! – Philip May 24 '12 at 11:49
1

I don't quite understand what you've done to apparently fix this because I believe it is actually a bug in redis-namespace. Please see issue #38.

Chewi
  • 530
  • 3
  • 4
  • 1
    And put this in your gemfile as @Narkoz wrote gem 'redis-namespace', '~> 1.0.2' – Philip May 24 '12 at 13:11
  • 1
    Forcing that version of redis-namespace probably did the trick but the problem is ultimately caused by the issue I posted. – Chewi May 24 '12 at 13:19
0

I had the wrong version of redis installed on the server. Instead of using apt-get install redis-server I manually installed redis-server and that solved the problem!

Philip
  • 6,827
  • 13
  • 75
  • 104