class Sidekiq::RedisClientAdapter

Constants

BaseError
CommandError
CompatClient
DEPRECATED_COMMANDS

You can add/remove items or clear the whole thing if you don’t want deprecation warnings.

Public Class Methods

new(options) click to toggle source
# File lib/sidekiq/redis_client_adapter.rb, line 63
def initialize(options)
  opts = client_opts(options)
  @config = if opts.key?(:sentinels)
    RedisClient.sentinel(**opts)
  elsif opts.key?(:nodes)
    # Sidekiq does not support Redis clustering but Sidekiq Enterprise's
    # rate limiters are cluster-safe so we can scale to millions
    # of rate limiters using a Redis cluster. This requires the
    # `redis-cluster-client` gem.
    # Sidekiq::Limiter.redis = { nodes: [...] }
    RedisClient.cluster(**opts)
  else
    RedisClient.config(**opts)
  end
end

Public Instance Methods

new_client() click to toggle source
# File lib/sidekiq/redis_client_adapter.rb, line 79
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 85
def client_opts(options)
  opts = options.dup

  if opts[:namespace]
    raise ArgumentError, "Your Redis configuration uses the namespace '#{opts[:namespace]}' but this feature is no longer supported in Sidekiq 7+. See https://github.com/sidekiq/sidekiq/blob/main/docs/7.0-Upgrade.md#redis-namespace."
  end

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

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

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

  # 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