+begin
+ # Timeout code is courtesy of Ruby memcache-client
+ # http://github.com/mperham/memcache-client/tree
+ # Try to use the SystemTimer gem instead of Ruby's timeout library
+ # when running on something that looks like Ruby 1.8.x. See:
+ # http://ph7spot.com/articles/system_timer
+ # We don't want to bother trying to load SystemTimer on jruby and
+ # ruby 1.9+.
+ if defined?(JRUBY_VERSION) || (RUBY_VERSION >= '1.9')
+ require 'timeout'
+ RedisTimer = Timeout
+ else
+ require 'system_timer'
+ RedisTimer = SystemTimer
+ end
+rescue LoadError => e
+ puts "[redis-rb] Could not load SystemTimer gem, falling back to Ruby's slower/unsafe timeout library: #{e.message}"
+ require 'timeout'
+ RedisTimer = Timeout
+end
+