OTP process that owns the TCP listener, manages connection processes, holds the in-memory store and mock rules, and implements Redis command semantics.
Users normally interact with this module indirectly via the FauxRedis
facade, but the functions here are public to make supervision and advanced
control easier when needed.
Summary
Functions
Registers a new stub or expectation rule.
Returns the list of recorded calls, ordered from oldest to newest.
Returns a child spec suitable for supervision trees.
Returns the TCP port the server is listening on.
Resets the server state (store, rules, history, auth, pub/sub).
Starts a new server process.
Types
@type mode() :: :mock_first | :stateful_only | :mock_only
Internal server mode.
@type t() :: %FauxRedis.Server{ authed: MapSet.t(non_neg_integer()), calls: [FauxRedis.call_record()], channels: %{required(binary()) => MapSet.t(pid())}, connections: %{required(non_neg_integer()) => pid()}, ets_kv: term(), listener: port() | nil, max_calls: pos_integer(), mode: mode(), next_conn_id: non_neg_integer(), password: binary() | nil, port: non_neg_integer() | nil, require_auth?: boolean(), rules: [FauxRedis.MockRule.t()], store: FauxRedis.Store.t(), subscriptions: %{required(pid()) => MapSet.t(binary())} }
Server state kept in the GenServer.
Functions
@spec add_rule(GenServer.server(), FauxRedis.MockRule.kind(), Keyword.t()) :: {:ok, reference()}
Registers a new stub or expectation rule.
This is the backing implementation for FauxRedis.stub/2, stub/3
and FauxRedis.expect/3.
@spec calls(GenServer.server()) :: [FauxRedis.call_record()]
Returns the list of recorded calls, ordered from oldest to newest.
@spec child_spec(Keyword.t()) :: Supervisor.child_spec()
Returns a child spec suitable for supervision trees.
@spec port(GenServer.server()) :: non_neg_integer()
Returns the TCP port the server is listening on.
@spec reset!(GenServer.server()) :: :ok
Resets the server state (store, rules, history, auth, pub/sub).
@spec start_link(Keyword.t()) :: GenServer.on_start()
Starts a new server process.
Options:
:port– TCP port to listen on (0 = random free port, default):mode–:mock_first(default),:stateful_only, or:mock_only:require_auth?– whether AUTH is required before most commands:password– the expected password for AUTH:name– optional registered name (e.g. viaRegistry)