Ferricstore.Commands.Catalog (ferricstore v0.3.1)

Copy Markdown View Source

Central registry of all commands supported by FerricStore.

Each entry contains the command name, arity (negative = variadic), flags, first-key / last-key / step indices, and a short summary string.

This module is the single source of truth consumed by:

  • COMMAND COUNT
  • COMMAND LIST
  • COMMAND INFO
  • COMMAND DOCS
  • COMMAND GETKEYS

Arity convention (Redis)

  • Positive N — command takes exactly N arguments (including the command name).
  • Negative N — command takes at least |N| arguments.

Key position convention

  • first_key: 0 means the command has no key arguments.
  • For single-key commands: first_key: 1, last_key: 1, step: 1.
  • For multi-key variadic commands: last_key: -1, step: 1.

Summary

Functions

Returns the full list of command entries.

Returns the number of supported commands.

Extracts the key arguments from a command invocation.

Same as get_keys/2 but accepts an already-uppercase command name, avoiding the String.downcase/1 call inside lookup/1.

Returns the Redis-style info tuple for a command entry.

Looks up a command entry by name (case-insensitive).

Looks up a command entry by an already-uppercase name.

Returns all command names as lowercase strings.

Types

command_entry()

@type command_entry() :: %{
  name: binary(),
  arity: integer(),
  flags: [binary()],
  first_key: integer(),
  last_key: integer(),
  step: integer(),
  summary: binary()
}

Functions

all()

@spec all() :: [command_entry()]

Returns the full list of command entries.

count()

@spec count() :: non_neg_integer()

Returns the number of supported commands.

get_keys(name, args)

@spec get_keys(binary(), [binary()]) :: {:ok, [binary()]} | {:error, binary()}

Extracts the key arguments from a command invocation.

Given a command name and its arguments list, returns the arguments that are keys based on the catalog's first_key/last_key/step metadata.

Returns {:ok, keys} or {:error, reason}.

get_keys_upper(name, args)

@spec get_keys_upper(binary(), [binary()]) :: {:ok, [binary()]} | {:error, binary()}

Same as get_keys/2 but accepts an already-uppercase command name, avoiding the String.downcase/1 call inside lookup/1.

info_tuple(cmd)

@spec info_tuple(command_entry()) :: list()

Returns the Redis-style info tuple for a command entry.

Format: [name, arity, [flags...], first_key, last_key, step]

lookup(name)

@spec lookup(binary()) :: {:ok, command_entry()} | :error

Looks up a command entry by name (case-insensitive).

Returns {:ok, entry} or :error.

lookup_upper(name)

@spec lookup_upper(binary()) :: {:ok, command_entry()} | :error

Looks up a command entry by an already-uppercase name.

Avoids the String.downcase/1 call in lookup/1 when the caller already has an uppercase command name (e.g. from normalise_cmd).

Returns {:ok, entry} or :error.

names()

@spec names() :: [binary()]

Returns all command names as lowercase strings.