class Roundhouse::RedisConnection

Public Class Methods

create(options={}) click to toggle source
# File lib/roundhouse/redis_connection.rb, line 9
def create(options={})
  options[:url] ||= determine_redis_provider

  # need a connection for Fetcher and Retry
  size = options[:size] || (Roundhouse.server? ? (Roundhouse.options[:concurrency] + 2) : 5)
  pool_timeout = options[:pool_timeout] || 1

  log_info(options)

  ConnectionPool.new(:timeout => pool_timeout, :size => size) do
    build_client(options)
  end
end

Private Class Methods

build_client(options) click to toggle source
# File lib/roundhouse/redis_connection.rb, line 25
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/roundhouse/redis_connection.rb, line 37
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[:driver] = opts[:driver] || 'ruby'

  opts
end
determine_redis_provider() click to toggle source
# File lib/roundhouse/redis_connection.rb, line 71
def determine_redis_provider
  ENV[ENV['REDIS_PROVIDER'] || 'REDIS_URL']
end
log_info(options) click to toggle source
# File lib/roundhouse/redis_connection.rb, line 53
def log_info(options)
  # Don't log Redis AUTH password
  redacted = "REDACTED"
  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
  if scrubbed_options[:password]
    scrubbed_options[:password] = redacted
  end
  if Roundhouse.server?
    Roundhouse.logger.info("Booting Roundhouse #{Roundhouse::VERSION} with redis options #{scrubbed_options}")
  else
    Roundhouse.logger.debug("#{Roundhouse::NAME} client with redis options #{scrubbed_options}")
  end
end