Botica.Batteries.Redis (Botica v2.1.0)

Copy Markdown View Source

Predefined health check for Redis cache server.

This module provides a ready-to-use check that verifies Redis is accessible. It prefers the redis-cli binary and falls back to a raw TCP port check (via Trebejo.Network.port_open?/3) when the binary is not installed.

All command execution is routed through Command.execute/2 so consumers get the full Arrea infra for free: real timeout cancellation, validation, telemetry, shell handling, and the sudo allowlist configured in config/config.exs.

Installation

Optional: install redis-cli (ships with the redis-tools / redis-server packages on most distros). Without it, the battery degrades to a raw TCP probe on the configured port.

Usage

config = %{
  app_name: "myapp",
  checks: [
    Botica.Batteries.Redis.check()
  ]
}

Options

  • :host - Redis host (default: "localhost")
  • :port - Redis port (default: 6379)
  • :timeout - Check timeout in ms (default: 5000)

Summary

Functions

Checks if Redis is responding to PING.

Attempts to start the Redis service.

Functions

check_connection(host, port)

@spec check_connection(String.t(), non_neg_integer()) :: Botica.Types.check_result()

Checks if Redis is responding to PING.

Uses redis-cli when available. Falls back to a TCP probe on the configured port via Trebejo.Network.port_open?/3 when the binary is not installed.

start_service()

@spec start_service() :: Botica.Types.fix_result()

Attempts to start the Redis service.

Tries systemctl start redis-server first, falls back to systemctl start redis for distros that name the unit differently. Requires sudo NOPASSWD configured for those systemctl calls (see config :arrea, :engine, sudo_allowlist in config/config.exs).