Reputation: 12721
I'm trying to get rails connect to redis by following this tutorial.
But I'm getting the following error when I try $redis = Redis.new(:host => 'localhost', :port => 6379)
or even just Redis.new
. I've tried the new notation as well (host: 'localhost',port: 6379)
. Redis works (ping-PONG test via redis-cli passes).
ArgumentError: odd number of arguments for Hash
from /var/lib/gems/1.9.1/gems/redis-2.1.1/lib/redis.rb:65:in `[]'
from /var/lib/gems/1.9.1/gems/redis-2.1.1/lib/redis.rb:65:in `info'
from /var/lib/gems/1.9.1/gems/redis-2.1.1/lib/redis.rb:606:in `inspect'
from /var/lib/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /var/lib/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /var/lib/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
What am I doing wrong?
Config Details:
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ rails -v
Rails 4.0.0
Upvotes: 2
Views: 3407
Reputation: 1244
I've ran into the same error. The first thing I notices is that this error is related to the visual output that gets displayed in the console as a representation of the object. The inspect
method is what gets called for this purpose. See the following from the stack trace:
/var/lib/gems/1.9.1/gems/redis-2.1.1/lib/redis.rb:606:in 'inspect'
So if you do redis = Redis.new(:host => 'localhost', :port => 6379)
or anytime you type just redis
therafter, you'll get this error. However if you ignore it and just do
redis.get 'foo'
everything works just fine.
Upvotes: 0
Reputation: 133
Had the following issue but we couldn't upgrade the redis gem to 3.x. It turned out that redis-rb was looking for a key/value pair for the redis config which didn't exist when running redis-server
.
Running redis-server with the config file
redis-server /usr/local/etc/redis.conf
fixed the issue.
Upvotes: 2
Reputation: 3326
I had the very same issue, turns out homebrew
had updated my redis-server
from 2.6.x to 2.8.6
I reverted back to an older version of redis and it worked!
Upvotes: 0
Reputation: 91
I haven't used redis yet, but based on a cursory look, seems like you're using the redis-ruby library. You probably want to experiment with redis-rails when it's available!(http://rubygems.org/gems/redis-rails)
The easiest way out is, look for Gemfile, and remove information about the redis gem. Replace that line with:
gem 'redis-rails'
Save the file, then run:
$ bundle install
Upvotes: 1
Reputation: 494
I receive the same error using the redis gem version 2.1.1. Try to update the redis gem to latest, which is version 3.0.4.
To update the redis gem, you can either run
gem update redis
to update the locally installed version, or run
bundle update redis
to update the redis gem that is installed as part of your Gemfile.
$ irb
1.9.3p392 :001 > require 'redis'
=> true
1.9.3p392 :002 > Redis.new(:host => 'localhost', :port => 6379)
ArgumentError: odd number of arguments for Hash
from /Users/zachallett/.rvm/gems/ruby-1.9.3-p392/gems/redis-2.1.1/lib/redis.rb:65:in `[]'
from /Users/zachallett/.rvm/gems/ruby-1.9.3-p392/gems/redis-2.1.1/lib/redis.rb:65:in `info'
from /Users/zachallett/.rvm/gems/ruby-1.9.3-p392/gems/redis-2.1.1/lib/redis.rb:606:in `inspect'
from /Users/zachallett/.rvm/rubies/ruby-1.9.3-p392/bin/irb:16:in `<main>'
.
$ irb
1.9.3p392 :001 > require 'redis'
=> true
1.9.3p392 :002 > Redis.new(:host => 'localhost', :port => 6379)
=> #<Redis client v3.0.4 for redis://localhost:6379/0>
Upvotes: 7