redix_sentinel v0.6.1 RedixSentinel View Source
RedixSentinel provides support for sentinels. A Redix process is
started as child process with :exit_on_disconnection
set to true
and the reconnection is handled by the parent process. All the
functions except start_link/3
has the same API interface as Redix
Example
sentinels = [
[host: "sentinel_3", port: 30000],
[host: "sentinel_2", port: 20000],
[host: "sentinel_1", port: 10000]
]
{:ok, pid} = RedixSentinel.start_link([group: "demo", sentinels: sentinels, role: "master"])
{:ok, "PONG"} = RedixSentinel.command(pid, ["PING"])
Supervisor Example
sentinels = [
[host: "sentinel_3", port: 30000],
[host: "sentinel_2", port: 20000],
[host: "sentinel_1", port: 10000]
]
children = [
{RedixSentinel, [[group: "demo", sentinels: sentinels, role: "master"], [], [name: :sentinel]]}
]
{:ok, _pid} = Supervisor.start_link(children, strategy: :one_for_one)
{:ok, "PONG"} = RedixSentinel.command(:sentinel, ["PING"])
Link to this section Summary
Functions
Creates a connection to redis server via the information obtained from one of the sentinels. Follows the protocol specified in https://redis.io/topics/sentinel-clients to obtain the server’s host and port information
Link to this section Types
Link to this section Functions
command(GenServer.server, command, Keyword.t) :: {:ok, Redix.Protocol.redis_value} | {:error, atom | Redix.Error.t}
see Redix.command/3
.
command!(GenServer.server, command, Keyword.t) :: Redix.Protocol.redis_value | no_return
see Redix.command!/3
.
pipeline(GenServer.server, [command], Keyword.t) :: {:ok, [Redix.Protocol.redis_value]} | {:error, atom}
see Redix.pipeline/3
.
pipeline!(GenServer.server, [command], Keyword.t) :: [Redix.Protocol.redis_value] | no_return
see Redix.pipeline!/3
.
start_link(Keyword.t, Keyword.t, Keyword.t) :: GenServer.on_start
Creates a connection to redis server via the information obtained from one of the sentinels. Follows the protocol specified in https://redis.io/topics/sentinel-clients to obtain the server’s host and port information.
Sentinel Options
:sentinels
- List of sentinel address. Each address should be a keyword list withhost (string)
andport (integer)
fields.:role
- (string) Role of the server. Should be either"master"
or"slave"
. Defaults to"master"
.:group
- (string) Name of the redis sentinel group.
Redis Connection Options
The host and port obtained via sentinel will be merged with this option and passed as the first option to Redix.start_link/2
Redix Behaviour Options
Please refer Redix.start_link/2
for the list of
options. :sync_connect
and :exit_on_disconnection
are not
supported. All the extra options like :name
are forwarded to the
GenServer.start_link/3
stop(GenServer.server, timeout) :: :ok
see Redix.stop/2
.