GenServer managing a single redis-server process.
Starts redis-server with a generated config file, tracks the OS PID, and sends SHUTDOWN NOSAVE on terminate (unless detached).
Usage
{:ok, pid} = RedisServerWrapper.Server.start_link(port: 6400, password: "secret")
RedisServerWrapper.Server.ping(pid)
RedisServerWrapper.Server.run(pid, ["SET", "key", "value"])
RedisServerWrapper.Server.stop(pid)Options
Typed options from RedisServerWrapper.Config are supported, subject to
Server-owned lifecycle fields. In particular, Server owns :daemonize,
:pidfile, and :dir, and interprets :timeout as its startup timeout
rather than Redis's idle-client directive. The shipped configuration guide
is the authoritative option matrix.
:redis_server_bin- path to redis-server binary (default: "redis-server"):redis_cli_bin- path to redis-cli binary (default: "redis-cli"):username- optional named ACL user paired with:password:port- plaintext TCP port; use0to disable plaintext TCP:unixsocket- Unix socket path used when TCP and TLS are disabled:tls_port- TLS listener and lifecycle connection port:tls_cert_file,:tls_key_file- Redis TLS server identity:tls_ca_cert_fileor:tls_ca_cert_dir- trusted CA for Redis and redis-cli:tls_client_cert_file,:tls_client_key_file- optional redis-cli identity:tls_server_name- optional redis-cli SNI name:tls_insecure- explicitly disable redis-cli certificate verification:distribution-:core(default),:full, or:legacy_stack. Only explicit:legacy_stackselection enables legacy Stack module discovery; caller-provided:loadmoduleentries always remain explicit.:name- GenServer name registration:timeout- startup timeout in ms (default: 10_000):loadmodule- Redis modules to load; accepts module paths or{path, [args]}tuples (default:[]):managed- controls how the redis-server OS process is tied to the BEAM:true(default) - redis-server runs as a Port tied to the BEAM lifecycle. When the BEAM exits, the port closes and redis-server receives SIGHUP. Teardown runs interminate/2, which is skipped on a:brutal_killsupervisor shutdown or a hard BEAM death, so the OS process can be stranded.:forcola- redis-server runs in the foreground under aForcola.Daemon, which guarantees the OS process group is killed and confirmed dead on owner death or supervisor shutdown, including the paths whereterminate/2never runs. Requires the optional:forcoladependency ({:forcola, "~> 0.3"});start_linkreturns{:error, :forcola_not_available}if it is missing.false- redis-server daemonizes independently (legacy behavior); the caller owns the OS process lifecycle.
Summary
Functions
Returns true if the redis-server OS process is still alive.
Returns a specification to start this module under a supervisor.
Returns the Cli struct for direct use.
Returns the default redis-server binary for a distribution.
Detaches the server -- the redis-server OS process will NOT be stopped
when this GenServer terminates. Returns {:error, :managed_server} in managed mode.
Returns connection and process information.
Pings the server. Returns true if alive.
Runs an arbitrary redis-cli command against this server.
Starts a redis-server process without linking.
Starts and links a redis-server process.
Gracefully stops the GenServer (which stops redis-server unless detached).
Types
@type distribution() :: :core | :full | :legacy_stack
@type managed() :: boolean() | :forcola
@type t() :: %RedisServerWrapper.Server{ cli: RedisServerWrapper.Cli.t(), config: RedisServerWrapper.Config.t(), daemon: pid() | nil, detached: boolean(), distribution: distribution(), managed: managed(), node_dir: String.t() | nil, pid: non_neg_integer() | nil, port_ref: port() | nil, redis_server_bin: String.t() }
Functions
@spec alive?(GenServer.server()) :: boolean()
Returns true if the redis-server OS process is still alive.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec cli(GenServer.server()) :: RedisServerWrapper.Cli.t()
Returns the Cli struct for direct use.
@spec default_server_bin(distribution()) :: String.t()
Returns the default redis-server binary for a distribution.
Core and Redis 8 Full use redis-server from PATH. Legacy Redis Stack is
opt-in and uses REDIS_LEGACY_STACK_SERVER_BIN when set, otherwise
redis-stack-server.
@spec detach(GenServer.server()) :: :ok | {:error, :managed_server}
Detaches the server -- the redis-server OS process will NOT be stopped
when this GenServer terminates. Returns {:error, :managed_server} in managed mode.
@spec info(GenServer.server()) :: map()
Returns connection and process information.
@spec ping(GenServer.server()) :: boolean()
Pings the server. Returns true if alive.
@spec run(GenServer.server(), [String.t()]) :: {:ok, String.t()} | {:error, String.t()}
Runs an arbitrary redis-cli command against this server.
@spec start(keyword()) :: GenServer.on_start()
Starts a redis-server process without linking.
@spec start_link(keyword()) :: GenServer.on_start()
Starts and links a redis-server process.
@spec stop(GenServer.server()) :: :ok
Gracefully stops the GenServer (which stops redis-server unless detached).