Trebejo.Redis (Trebejo v2.0.0)

Copy Markdown View Source

Redis client wrapper around redis-cli.

Routes everything through Trebejo.Util.run_cmd/3 (via Trebejo.Runner) so it picks up :timeout, the circuit breaker, and Trebejo.Mox mocking automatically.

Designed for ad-hoc shell-friendly operations (info, ping, config tweaks, monitoring) rather than a high-throughput data path. For production workloads consider :redix or :eredis directly.

Options (shared)

  • :host — -h, default 127.0.0.1
  • :port — -p, default 6379
  • :password — -a, passed via the CLI flag (NOT as an env var; see :auth for the env-var alternative)
  • :auth — [:env] uses REDISCLI_AUTH env var instead of -a
  • :database — -n, default 0
  • :tls — --tls if true
  • :timeout — passed through to the underlying runner
  • :breaker — circuit breaker name

Examples

iex> Trebejo.Redis.run(["PING"])
{:ok, "PONG\n", 0}

iex> Trebejo.Redis.run(["INFO", "server"], host: "redis.internal", port: 6380)
{:ok, "# Server\n...", 0}

Summary

Functions

Stream a long-running MONITOR session. Returns a Trebejo.Stream.lines/3 enumerable of events.

Shortcut for PING. Returns true if the server responds PONG.

Run a redis-cli command given as a list of args.

Functions

monitor(opts \\ [])

@spec monitor(keyword()) :: {:ok, Enumerable.t()} | {:error, Trebejo.Error.t()}

Stream a long-running MONITOR session. Returns a Trebejo.Stream.lines/3 enumerable of events.

ping?(opts \\ [])

@spec ping?(keyword()) :: boolean()

Shortcut for PING. Returns true if the server responds PONG.

run(args, opts \\ [])

@spec run(
  [String.t()],
  keyword()
) :: {:ok, String.t(), 0} | {:error, Trebejo.Error.t()}

Run a redis-cli command given as a list of args.

Returns {:ok, stdout, 0} on success or {:error, %Trebejo.Error{}} on failure (non-zero exit, missing binary, timeout, breaker open).