Method: Redis#initialize

Defined in:
lib/redis.rb

#initialize(options = {}) ⇒ Redis

Create a new client instance

Parameters:

  • 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: "127.0.0.1"

    server hostname

  • :port (Fixnum) — 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

  • :password (String)

    Password to authenticate against server

  • :db (Fixnum) — 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, Fixnum)

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

  • :reconnect_attempts (Fixnum)

    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

  • :connector (Class)

    Class of custom connector



41
42
43
44
45
46
47
48
49
# File 'lib/redis.rb', line 41

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

  super() # Monitor#initialize
end