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

Link to this section Types

Link to this type command() View Source
command() :: [binary]

Link to this section Functions

Link to this function command(conn, command, opts \\ []) View Source

see Redix.command/3.

Link to this function pipeline(conn, commands, opts \\ []) View Source
pipeline(GenServer.server, [command], Keyword.t) ::
  {:ok, [Redix.Protocol.redis_value]} |
  {:error, atom}

see Redix.pipeline/3.

Link to this function pipeline!(conn, commands, opts \\ []) View Source

see Redix.pipeline!/3.

Link to this function start_link(sentinel_opts, redis_connection_options \\ [], redix_opts \\ []) View Source

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 with host (string) and port (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

Link to this function stop(conn, timeout \\ :infinity) View Source
stop(GenServer.server, timeout) :: :ok

see Redix.stop/2.