Skip to content

Instantly share code, notes, and snippets.

@dennisfaust
Created November 8, 2012 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennisfaust/4042408 to your computer and use it in GitHub Desktop.
Save dennisfaust/4042408 to your computer and use it in GitHub Desktop.
Ruby/Redis Connection - redis-rb doesn't throw an exception until you try to do something...
#
# Check: http://redis-rb.keyvalue.org/v2.2.0/
#
if Redis_connect
case Rails.env
when "production"
opts = {:host => "YOUR HOST NAME OR IP", :port => "6379", :thread_safe => true }
when "staging"
opts = {:host => "YOUR HOST NAME OR IP", :port => "6379", :thread_safe => true }
else
opts = {:host => "localhost", :port => "6379", :thread_safe => true }
end
begin
$redis ||= Redis.new(opts)
puts ("Redis connected to: #{$redis.inspect}")
$redis.set("foo","test")
f = $redis.get("foo")
raise if f != "test"
rescue Redis::CannotConnectError
puts("Redis connect error: #{$!.inspect}")
$redis = Redis.new(opts)
raise( $redis )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment