Parses and validates blocking list commands: BLPOP, BRPOP, BLMOVE, BLMPOP.
These commands are not dispatched through the normal Dispatcher because
they require connection-level blocking (the connection process enters a
receive block). Instead, Connection calls this module to parse args and
then handles the blocking logic itself.
Blocking semantics
When the target list is non-empty, the command executes immediately (pop and
return). When the list is empty, the connection process registers as a waiter
in the Ferricstore.Waiters ETS table and enters a receive block with an
after clause for the timeout. When another client pushes to the watched key,
the waiter is notified via {:waiter_notify, key}. The BEAM runtime handles
the timeout with zero polling.
Supported commands
BLPOP key [key ...] timeout-- block until left popBRPOP key [key ...] timeout-- block until right popBLMOVE source destination LEFT|RIGHT LEFT|RIGHT timeout-- blocking LMOVEBLMPOP timeout numkeys key [key ...] LEFT|RIGHT [COUNT count]-- blocking LMPOP
Summary
Functions
Parses BLMOVE arguments into {:ok, source, destination, from_dir, to_dir, timeout_ms}.
Parses BLMPOP arguments.
Parses BLPOP/BRPOP arguments into {:ok, keys, timeout_ms} or {:error, msg}.
Parses BRPOPLPUSH arguments into {:ok, source, destination, timeout_ms} or {:error, msg}.
Functions
@spec parse_blmove_args([binary()]) :: {:ok, binary(), binary(), :left | :right, :left | :right, non_neg_integer()} | {:error, binary()}
Parses BLMOVE arguments into {:ok, source, destination, from_dir, to_dir, timeout_ms}.
Parameters
args--[source, destination, wherefrom, whereto, timeout]
Returns
{:ok, source, destination, from_dir, to_dir, timeout_ms}{:error, reason}
@spec parse_blmpop_args([binary()]) :: {:ok, [binary()], :left | :right, pos_integer(), non_neg_integer()} | {:error, binary()}
Parses BLMPOP arguments.
Format: timeout numkeys key [key ...] LEFT|RIGHT [COUNT count]
Returns
{:ok, keys, direction, count, timeout_ms}{:error, reason}
@spec parse_blpop_args([binary()]) :: {:ok, [binary()], non_neg_integer()} | {:error, binary()}
Parses BLPOP/BRPOP arguments into {:ok, keys, timeout_ms} or {:error, msg}.
The last argument is the timeout in seconds (float or integer). All preceding arguments are keys.
Parameters
args-- list of string arguments
Returns
{:ok, keys, timeout_ms}-- parsed keys and timeout in milliseconds{:error, reason}-- parse error
@spec parse_brpoplpush_args([binary()]) :: {:ok, binary(), binary(), non_neg_integer()} | {:error, binary()}
Parses BRPOPLPUSH arguments into {:ok, source, destination, timeout_ms} or {:error, msg}.
Format: source destination timeout
Parameters
args-- list of string arguments:[source, destination, timeout]
Returns
{:ok, source, destination, timeout_ms}-- parsed arguments{:error, reason}-- parse error