Ferricstore.Commands.Dispatcher (ferricstore v0.3.4)

Copy Markdown View Source

Routes Redis command names to the appropriate handler module.

The dispatcher normalises the command name to uppercase and delegates to one of:

Multi-word commands (CLIENT, COMMAND) are routed based on the first word, then the subcommand is extracted from args. CLIENT subcommands require connection state and are dispatched via dispatch_client/3.

Unknown commands return {:error, "ERR unknown command ..."}.

Summary

Functions

Dispatches a Redis command to the appropriate handler module.

Functions

dispatch(name, args, store)

@spec dispatch(binary(), [binary()], map()) :: term()

Dispatches a Redis command to the appropriate handler module.

The command name is normalised to uppercase before routing. Each handler receives (cmd, args, store) and returns plain Elixir terms.

Parameters

  • name - Command name (any case)
  • args - List of string arguments
  • store - Injected store map

Returns

The return value from the matched handler, or {:error, message} for unknown commands.

Examples

iex> store = %{get: fn "k" -> "v" end}
iex> Ferricstore.Commands.Dispatcher.dispatch("GET", ["k"], store)
"v"