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-:primaryor: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-:resp3or: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
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec command(GenServer.server(), [String.t()], keyword()) :: {:ok, term()} | {:error, term()}
Sends a command through the sentinel-managed connection.
@spec info(GenServer.server()) :: map()
Returns info about the current connection.
@spec pipeline(GenServer.server(), [[String.t()]], keyword()) :: {:ok, [term()]} | {:error, term()}
@spec start_link(keyword()) :: GenServer.on_start()
@spec stop(GenServer.server()) :: :ok
@spec transaction(GenServer.server(), [[String.t()]], keyword()) :: {:ok, [term()]} | {:error, term()}