FauxRedis.MockEngine (faux_redis v1.0.2)

Copy Markdown View Source

Evaluation engine for mock and expectation rules.

It is responsible for:

  • matching incoming commands against configured rules
  • supporting sequence responses (lists) and callback functions
  • tracking usage counts for expectations
  • returning a concrete response specification for the connection layer

Summary

Types

Result of rule evaluation.

Functions

Applies mock/expectation rules according to the given mode.

Types

result()

@type result() :: %{
  response: term(),
  rule_id: reference() | nil,
  rules: [FauxRedis.MockRule.t()]
}

Result of rule evaluation.

Functions

apply(rules, command, mode, fallback)

@spec apply(
  [FauxRedis.MockRule.t()],
  FauxRedis.Command.t(),
  :mock_first | :mock_only | :stateful_only,
  (-> term())
) :: result()

Applies mock/expectation rules according to the given mode.

Modes:

  • :mock_first – try rules, fall back to fallback.() when no match
  • :mock_only – try rules, return {:error, "ERR unknown command"} when no match
  • :stateful_only – ignore rules, always call fallback.()