我添加gem 'redis'
到我的 Gemfile。冉bundle install
。重新启动本地服务器,然后在我的控制台中运行 hello world 示例,结果出现错误。知道有什么问题吗?
[kudo (develop)]$ rails console
Loading development environment (Rails 3.2.3)
1.9.3p125 :001 > redis = Redis.new
=> #<Redis client v3.0.2 for redis://127.0.0.1:6379/0>
1.9.3p125 :002 > redis.set("mykey", "hello world")
Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis/client.rb:268:in `rescue in establish_connection'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis/client.rb:263:in `establish_connection'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis/client.rb:69:in `connect'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis/client.rb:282:in `ensure_connected'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis/client.rb:173:in `block in process'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis/client.rb:248:in `logging'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis/client.rb:172:in `process'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis/client.rb:84:in `call'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis.rb:608:in `block in set'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis.rb:36:in `block in synchronize'
from /Users/pejman/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis.rb:36:in `synchronize'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/redis-3.0.2/lib/redis.rb:607:in `set'
from (irb):2
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /Users/pejman/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'1.9.3p125 :003 >