class Sidekiq::RedisClientAdapter

Constants

BaseError
CommandError
CompatClient

Public Class Methods

new(options) click to toggle source
# File lib/sidekiq/redis_client_adapter.rb, line 102
def initialize(options)
  opts = client_opts(options)
  @config = if opts.key?(:sentinels)
    RedisClient.sentinel(**opts)
  else
    RedisClient.config(**opts)
  end
end

Public Instance Methods

new_client() click to toggle source
# File lib/sidekiq/redis_client_adapter.rb, line 111
def new_client
  CompatClient.new(@config.new_client)
end

Private Instance Methods

client_opts(options) click to toggle source
# File lib/sidekiq/redis_client_adapter.rb, line 117
def client_opts(options)
  opts = options.dup

  if opts[:namespace]
    Sidekiq.logger.error("Your Redis configuration uses the namespace '#{opts[:namespace]}' but this feature isn't supported by redis-client. " \
      "Either use the redis adapter or remove the namespace.")
    Kernel.exit(-127)
  end

  opts.delete(:size)
  opts.delete(:pool_timeout)

  if opts[:network_timeout]
    opts[:timeout] = opts[:network_timeout]
    opts.delete(:network_timeout)
  end

  if opts[:driver]
    opts[:driver] = opts[:driver].to_sym
  end

  opts[:name] = opts.delete(:master_name) if opts.key?(:master_name)
  opts[:role] = opts[:role].to_sym if opts.key?(:role)
  opts.delete(:url) if opts.key?(:sentinels)

  # Issue #3303, redis-rb will silently retry an operation.
  # This can lead to duplicate jobs if Sidekiq::Client's LPUSH
  # is performed twice but I believe this is much, much rarer
  # than the reconnect silently fixing a problem; we keep it
  # on by default.
  opts[:reconnect_attempts] ||= 1

  opts
end