class Shoryuken::RedisConnection

Public Class Methods

create(options = {}) click to toggle source
# File lib/shoryuken/redis_connection.rb, line 10
def create(options = {})
  options = options.symbolize_keys

  options[:url] ||= determine_redis_provider
  size = options[:size] || 5
  pool_timeout = options[:pool_timeout] || 1

  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/shoryuken/redis_connection.rb, line 24
def build_client(options)
  client = Redis.new client_opts(options)

  if (namespace = options[:namespace])
    begin
      require 'redis/namespace'
      Redis::Namespace.new(namespace, :redis => client)
    rescue LoadError
      Shoryken.logger.error("Your Redis configuration uses the namespace '#{namespace}' but the redis-namespace gem is not included in the Gemfile." \
                            'Add the gem to your Gemfile to continue using a namespace. Otherwise, remove the namespace parameter.')
      exit(-127)
    end
  else
    client
  end
end
client_opts(options) click to toggle source
# File lib/shoryuken/redis_connection.rb, line 41
def client_opts(options)
  opts = options.dup
  opts.delete(:namespace) if opts[:namespace]
  if opts[:network_timeout]
    opts[:timeout] = opts[:network_timeout]
    opts.delete(:network_timeout)
  end
  opts[:driver] ||= 'ruby'.freeze
  opts[:reconnect_attempts] ||= 1
  opts
end
determine_redis_provider() click to toggle source
# File lib/shoryuken/redis_connection.rb, line 53
def determine_redis_provider
  ENV[ENV['REDIS_PROVIDER'] || 'REDIS_URL']
end