RedisServerWrapper (redis_server_wrapper v0.7.3)

Copy Markdown View Source

Elixir wrapper for redis-server and redis-cli with GenServer-managed process lifecycles.

Manage Redis server processes for testing, development, and CI without Docker -- just redis-server and redis-cli on PATH.

Quick Start

# Single server
{:ok, server} = RedisServerWrapper.start_server(port: 6400, password: "secret")
RedisServerWrapper.Server.run(server, ["SET", "key", "value"])
RedisServerWrapper.Server.stop(server)

# Cluster
{:ok, cluster} = RedisServerWrapper.start_cluster(masters: 3, base_port: 7100)
RedisServerWrapper.Cluster.healthy?(cluster)
RedisServerWrapper.Cluster.stop(cluster)

# Sentinel
{:ok, sentinel} = RedisServerWrapper.start_sentinel(master_port: 6390, replicas: 2, sentinels: 3)
RedisServerWrapper.Sentinel.healthy?(sentinel)
RedisServerWrapper.Sentinel.stop(sentinel)

Features

  • Single server - start/stop with options, auto-cleanup on GenServer terminate
  • Cluster - spin up N-master clusters with optional replicas
  • Sentinel - full sentinel topology (master + replicas + sentinels)
  • Custom binaries - point to any redis-server/redis-cli path
  • Custom modules - load modules with argument-safe configuration on standalone servers, cluster nodes, and sentinel data nodes
  • Arbitrary config - pass any Redis directive via :extra option

Summary

Functions

Checks if redis-server is available on PATH (or at the given path).

Starts a Redis Cluster. See RedisServerWrapper.Cluster for options.

Starts a Redis Sentinel topology. See RedisServerWrapper.Sentinel for options.

Starts a single redis-server instance. See RedisServerWrapper.Server for options.

Returns the version of redis-server on PATH, or {:error, reason}.

Functions

available?(bin \\ "redis-server")

@spec available?(String.t()) :: boolean()

Checks if redis-server is available on PATH (or at the given path).

start_cluster(opts \\ [])

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

Starts a Redis Cluster. See RedisServerWrapper.Cluster for options.

start_sentinel(opts \\ [])

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

Starts a Redis Sentinel topology. See RedisServerWrapper.Sentinel for options.

start_server(opts \\ [])

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

Starts a single redis-server instance. See RedisServerWrapper.Server for options.

version(bin \\ "redis-server")

@spec version(String.t()) :: {:ok, String.t()} | {:error, term()}

Returns the version of redis-server on PATH, or {:error, reason}.