Method: Redis#initialize

Defined in:

#initialize(options = {}) ⇒ Redis

Create a new client instance


  • options (Hash) (defaults to: {})

Options Hash (options):

  • :url (String) — default: value of the environment variable REDIS_URL

    a Redis URL, for a TCP connection: `redis://:@[hostname]:/[db]` (password, port and database are optional), for a unix socket

    connection: `unix://[path to Redis socket]`. This overrides all other options.
  • :host (String) — default: ""

    server hostname

  • :port (Integer) — default: 6379

    server port

  • :path (String)

    path to server socket (overrides host and port)

  • :timeout (Float) — default: 5.0

    timeout in seconds

  • :connect_timeout (Float) — default: same as timeout

    timeout for initial connect in seconds

  • :username (String)

    Username to authenticate against server

  • :password (String)

    Password to authenticate against server

  • :db (Integer) — default: 0

    Database to select after initial connect

  • :driver (Symbol)

    Driver to use, currently supported: `:ruby`, `:hiredis`, `:synchrony`

  • :id (String)

    ID for the client connection, assigns name to current connection by sending `CLIENT SETNAME`

  • :tcp_keepalive (Hash, Integer)

    Keepalive values, if Integer `intvl` and `probe` are calculated based on the value, if Hash `time`, `intvl` and `probes` can be specified as a Integer

  • :reconnect_attempts (Integer)

    Number of attempts trying to connect

  • :inherit_socket (Boolean) — default: false

    Whether to use socket in forked process or not

  • :sentinels (Array)

    List of sentinels to contact

  • :role (Symbol) — default: :master

    Role to fetch via Sentinel, either `:master` or `:slave`

  • :cluster (Array<String, Hash{Symbol => String, Integer}>)

    List of cluster nodes to contact

  • :replica (Boolean)

    Whether to use readonly replica nodes in Redis Cluster or not

  • :fixed_hostname (String)

    Specify a FQDN if cluster mode enabled and client has to connect nodes via single endpoint with SSL/TLS

  • :connector (Class)

    Class of custom connector

# File 'lib/redis.rb', line 82

def initialize(options = {})
  @options = options.dup
  @cluster_mode = options.key?(:cluster)
  client = @cluster_mode ? Cluster : Client
  @original_client = @client =
  @queue = { |h, k| h[k] = [] }
  @monitor =