class Taskinator::RedisConnection
Public Class Methods
create(options={})
click to toggle source
# File lib/taskinator/redis_connection.rb, line 22 def create(options={}) url = options[:url] || determine_redis_provider if url options[:url] = url end pool_size = options[:pool_size] || 5 pool_timeout = options[:pool_timeout] || 1 log_info(options) ConnectionPool.new(:timeout => pool_timeout, :size => pool_size) do build_client(options) end end
Private Class Methods
build_client(options)
click to toggle source
# File lib/taskinator/redis_connection.rb, line 40 def build_client(options) namespace = options[:namespace] client = Redis.new client_opts(options) if namespace require 'redis/namespace' Redis::Namespace.new(namespace, :redis => client) else client end end
client_opts(options)
click to toggle source
# File lib/taskinator/redis_connection.rb, line 52 def client_opts(options) opts = options.dup if opts[:namespace] opts.delete(:namespace) end if opts[:network_timeout] opts[:timeout] = opts[:network_timeout] opts.delete(:network_timeout) end opts end
determine_redis_provider()
click to toggle source
# File lib/taskinator/redis_connection.rb, line 76 def determine_redis_provider ENV[ENV['REDIS_PROVIDER'] || 'REDIS_URL'] end
log_info(options)
click to toggle source
# File lib/taskinator/redis_connection.rb, line 66 def log_info(options) # Don't log Redis AUTH password scrubbed_options = options.dup if scrubbed_options[:url] && (uri = URI.parse(scrubbed_options[:url])) && uri.password uri.password = "REDACTED" scrubbed_options[:url] = uri.to_s end Taskinator.logger.info("#{Taskinator::NAME} client with redis options #{scrubbed_options}") end