class Redis

def _client

def _client
  @client
end

def _subscription(method, timeout, channels, block)

def _subscription(method, timeout, channels, block)
  if block
    if @subscription_client
      raise SubscriptionError, "This client is already subscribed"
    end
    begin
      @subscription_client = SubscribedClient.new(@client.pubsub)
      if timeout > 0
        @subscription_client.send(method, timeout, *channels, &block)
      else
        @subscription_client.send(method, *channels, &block)
      end
    ensure
      @subscription_client&.close
      @subscription_client = nil
    end
  else
    unless @subscription_client
      raise SubscriptionError, "This client is not subscribed"
    end
    @subscription_client.call_v([method].concat(channels))
  end
end

def close

Disconnect the client as quickly and silently as possible.
def close
  @client.close
  @subscription_client&.close
end

def connected?

Test whether or not the client is connected
def connected?
  @client.connected? || @subscription_client&.connected?
end

def connection

def connection
  {
    host: @client.host,
    port: @client.port,
    db: @client.db,
    id: id,
    location: "#{@client.host}:#{@client.port}"
  }
end

def deprecate!(message)

def deprecate!(message)
  unless silence_deprecations
    if raise_deprecations
      raise Deprecated, message
    else
      ::Kernel.warn(message)
    end
  end
end

def dup

def dup
  self.class.new(@options)
end

def id

def id
  @client.id || @client.server_url
end

def initialize(options = {})

Returns:
  • (Redis) - a new client instance

Options Hash: (**options)
  • :sentinels (Array) -- List of sentinels to contact
  • :name (String) -- The name of the server group to connect to.
  • :inherit_socket (Boolean) -- Whether to use socket in forked process or not
  • :reconnect_attempts (Integer, Array) -- Number of attempts trying to connect,
  • :id (String) -- ID for the client connection, assigns name to current connection by sending
  • :driver (Symbol) -- Driver to use, currently supported: `:ruby`, `:hiredis`
  • :db (Integer) -- Database to select after connect and on reconnects
  • :password (String) -- Password to authenticate against server
  • :username (String) -- Username to authenticate against server
  • :connect_timeout (Float) -- timeout for initial connect in seconds
  • :timeout (Float) -- timeout in seconds
  • :path (String) -- path to server socket (overrides host and port)
  • :port (Integer) -- server port
  • :host (String) -- server hostname
  • :url (String) -- a Redis URL, for a TCP connection:

Parameters:
  • options (Hash) --
def initialize(options = {})
  @monitor = Monitor.new
  @options = options.dup
  @options[:reconnect_attempts] = 1 unless @options.key?(:reconnect_attempts)
  if ENV["REDIS_URL"] && SERVER_URL_OPTIONS.none? { |o| @options.key?(o) }
    @options[:url] = ENV["REDIS_URL"]
  end
  inherit_socket = @options.delete(:inherit_socket)
  @subscription_client = nil
  @client = initialize_client(@options)
  @client.inherit_socket! if inherit_socket
end

def initialize_client(options)

def initialize_client(options)
  if options.key?(:cluster)
    raise "Redis Cluster support was moved to the `redis-clustering` gem."
  end
  if options.key?(:sentinels)
    Client.sentinel(**options).new_client
  else
    Client.config(**options).new_client
  end
end

def inspect

def inspect
  "#<Redis client v#{Redis::VERSION} for #{id}>"
end

def pipelined(exception: true)

def pipelined(exception: true)
  synchronize do |client|
    client.pipelined(exception: exception) do |raw_pipeline|
      yield PipelinedConnection.new(raw_pipeline, exception: exception)
    end
  end
end

def send_blocking_command(command, timeout, &block)

def send_blocking_command(command, timeout, &block)
  @monitor.synchronize do
    @client.blocking_call_v(timeout, command, &block)
  end
end

def send_command(command, &block)

def send_command(command, &block)
  @monitor.synchronize do
    @client.call_v(command, &block)
  end
rescue ::RedisClient::Error => error
  Client.translate_error!(error)
end

def synchronize

def synchronize
  @monitor.synchronize { yield(@client) }
end

def with

def with
  yield self
end

def without_reconnect(&block)

Run code without the client reconnecting
def without_reconnect(&block)
  @client.disable_reconnection(&block)
end