Redis.Connection.Pool (Redis v0.7.1)

Copy Markdown View Source

Connection pool for Redis.

Manages N Redis.Connection processes with round-robin dispatch. Dead connections are automatically replaced. Same API as a single connection.

Usage

{:ok, pool} = Redis.Connection.Pool.start_link(
  pool_size: 5,
  host: "localhost",
  port: 6379
)

{:ok, "OK"} = Redis.Connection.Pool.command(pool, ["SET", "key", "val"])
{:ok, "val"} = Redis.Connection.Pool.command(pool, ["GET", "key"])

Options

  • :pool_size - number of connections (default: 5)
  • :strategy - :round_robin or :random (default: :round_robin)
  • :name - GenServer name
  • All other options are passed to each Redis.Connection

Supervision

children = [
  {Redis.Connection.Pool, pool_size: 10, port: 6379, name: :redis_pool}
]

Summary

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

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

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

info(pool)

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

Returns pool info: size, active connections, strategy.

noreply_command(pool, args, opts \\ [])

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

noreply_pipeline(pool, commands, opts \\ [])

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

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

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

start_link(opts \\ [])

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

stop(pool)

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

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

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