Created
November 8, 2012 22:55
-
-
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...
This file contains 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
# | |
# 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