Redis.Sentinel (Redis v0.7.1)

Copy Markdown View Source

Sentinel-aware Redis connection.

Queries sentinels to discover the current primary or replica, then maintains a connection. On disconnection, re-queries sentinels to find the (possibly new) primary.

Usage

{:ok, conn} = Redis.Sentinel.start_link(
  sentinels: [{"sentinel1", 26379}, {"sentinel2", 26379}],
  group: "mymaster",
  role: :primary,
  password: "secret"
)

# Use like a normal connection — failover is transparent
{:ok, "OK"} = Redis.Sentinel.command(conn, ["SET", "key", "value"])

Options

  • :sentinels - list of sentinel addresses as {host, port} tuples or "host:port" strings (required)
  • :group - sentinel group name (required)
  • :role - :primary or :replica (default: :primary)
  • :password - password for the Redis server (not the sentinel)
  • :sentinel_password - password for sentinel connections
  • :username - username for the Redis server
  • :database - database number
  • :timeout - connection timeout ms (default: 5_000)
  • :sentinel_timeout - sentinel query timeout ms (default: 500)
  • :name - GenServer name registration
  • :protocol - :resp3 or :resp2 (default: :resp3)

Summary

Functions

Returns a specification to start this module under a supervisor.

Sends a command through the sentinel-managed connection.

Returns info about the current connection.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

command(sentinel, args, opts \\ [])

@spec command(GenServer.server(), [String.t()], keyword()) ::
  {:ok, term()} | {:error, term()}

Sends a command through the sentinel-managed connection.

info(sentinel)

@spec info(GenServer.server()) :: map()

Returns info about the current connection.

pipeline(sentinel, commands, opts \\ [])

@spec pipeline(GenServer.server(), [[String.t()]], keyword()) ::
  {:ok, [term()]} | {:error, term()}

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

stop(sentinel)

@spec stop(GenServer.server()) :: :ok

transaction(sentinel, commands, opts \\ [])

@spec transaction(GenServer.server(), [[String.t()]], keyword()) ::
  {:ok, [term()]} | {:error, term()}