Created
May 31, 2012 19:38
-
-
Save kwiest/2845726 to your computer and use it in GitHub Desktop.
Redis Cannot Connect Error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When I run the test when Redis is running, all tests pass | |
# When I run the test with Redis purposefully off, I get the error at the end of the gist | |
# | |
# I've tried manually raising Redis::CannotConnectError instead of calling Redis.new | |
# and a new instance of SimpleStore is returned, and again all tests pass | |
# Gemfile | |
gem 'redis', '~> 3.0.0' | |
# store.rb | |
require 'redis' | |
require 'singleton' | |
module CRS | |
class ActivityFeed | |
class Store | |
include Singleton | |
def delete!(key) | |
connection.del(key) | |
end | |
# Rest of instance methods... | |
private | |
def connection | |
if ENV['RAILS_ENV'] == 'production' | |
@host = ENV['REDIS_HOST'] | |
@port = 6379 | |
else | |
@host = 'localhost' | |
@port = 6379 | |
end | |
@connection ||= Redis.new(host: @host, port: @port) | |
rescue Redis::CannotConnectError | |
SimpleStore.new | |
end | |
end | |
class SimpleStore | |
# simple store class | |
end | |
end | |
end | |
# Output when I try to run store_test.rb | |
# Command: ruby -v -Itest test/unit/crs/activity_feed/store_test.rb | |
1) Error: | |
Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (ECONNREFUSED) | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis/client.rb:262:in `rescue in establish_connection' | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis/client.rb:257:in `establish_connection' | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis/client.rb:63:in `connect' | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis/client.rb:276:in `ensure_connected' | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis/client.rb:167:in `block in process' | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis/client.rb:242:in `logging' | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis/client.rb:166:in `process' | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis/client.rb:78:in `call' | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis.rb:607:in `block in set' | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis.rb:36:in `block in synchronize' | |
# Added `puts caller.join("\n") in redis.rb above line 36 | |
/Users/kwiest2000/.rvm/gems/ruby-1.9.3-head@crs/gems/redis-3.0.0/lib/redis.rb:368:in `del' | |
/Users/kwiest2000/Projects/Camp-Registration-Systems/app/models/crs/activity_feed/store.rb:15:in `delete!' | |
test/unit/crs/activity_feed/store_test.rb:41:in `test_trim' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:949:in `run' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:787:in `block in _run_suite' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:780:in `map' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:780:in `_run_suite' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:770:in `block in _run_suites' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:770:in `map' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:770:in `_run_suites' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:746:in `_run_anything' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:909:in `run_tests' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:896:in `block in _run' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:895:in `each' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:895:in `_run' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:884:in `run' | |
/Users/kwiest2000/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/minitest/unit.rb:664:in `block in autorun' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment