Hash slot router for Redis Cluster.
Computes CRC16 hash slots and extracts keys from commands for routing.
Summary
Functions
Extracts the first key from a Redis command for slot routing.
Extracts the keys referenced by a command.
Computes the hash slot for a key.
Extracts all keys from a command. For multi-key commands,
validates they all hash to the same slot.
Returns {:ok, slot} or {:error, :cross_slot}.
Validates that all commands in a pipeline target the same slot.
Functions
Extracts the first key from a Redis command for slot routing.
Extracts the keys referenced by a command.
Commands with dynamic key positions (such as EVAL, XREAD, and the
*MPOP family) and common multi-key commands are handled explicitly.
Unknown commands fall back to Redis' usual first-argument key convention.
@spec slot(String.t()) :: non_neg_integer()
Computes the hash slot for a key.
@spec slot_for_command([String.t()]) :: {:ok, non_neg_integer()} | {:error, :no_key} | {:error, :cross_slot}
Extracts all keys from a command. For multi-key commands,
validates they all hash to the same slot.
Returns {:ok, slot} or {:error, :cross_slot}.
@spec validate_pipeline([[String.t()]]) :: {:ok, non_neg_integer()} | {:error, :cross_slot} | {:error, :empty} | {:error, :no_key}
Validates that all commands in a pipeline target the same slot.