Command builders for Redis list operations.
This module provides pure functions that return Redis command lists for
list data type operations, including pushing/popping elements, range
queries, blocking pops, and atomic moves between lists. All functions
return a list of strings suitable for use with Redis.command/2 or
Redis.pipeline/2.
Examples
# Push multiple elements to the head and tail of a list
iex> Redis.Commands.List.lpush("queue", ["c", "b", "a"])
["LPUSH", "queue", "c", "b", "a"]
iex> Redis.Commands.List.rpush("queue", ["x", "y"])
["RPUSH", "queue", "x", "y"]
# Retrieve a range of elements (0-based, inclusive)
iex> Redis.Commands.List.lrange("queue", 0, -1)
["LRANGE", "queue", "0", "-1"]
# Blocking pop with a 5-second timeout
iex> Redis.Commands.List.blpop(["queue1", "queue2"], 5)
["BLPOP", "queue1", "queue2", "5"]
# Atomically move an element between lists
iex> Redis.Commands.List.lmove("src", "dst", "LEFT", "RIGHT")
["LMOVE", "src", "dst", "LEFT", "RIGHT"]
Summary
Functions
Builds a BLPOP command to perform a blocking pop from the head of one or
more lists. The call blocks for up to timeout seconds until an element
becomes available. A timeout of 0 blocks indefinitely.
Deprecated: use blmove/5 instead.
Builds an LMOVE command to atomically pop an element from source and
push it to destination. Use wherefrom and whereto ("LEFT" or
"RIGHT") to control which end of each list is used.
Builds an LPOP command to remove and return the first element of the list
at key. When count is provided, removes and returns up to count
elements from the head.
Builds an LPUSH command to prepend one or more values to the head of
the list at key. Elements are inserted one after another from left to
right, so the last element in the list will be the first in the resulting
list. Returns the length of the list after the push.
Builds an LRANGE command to return elements from index start to stop
(inclusive) in the list at key. Indices are 0-based; negative indices
count from the end (-1 is the last element).
Builds an RPOP command to remove and return the last element of the list
at key. When count is provided, removes and returns up to count
elements from the tail.
Deprecated: use lmove/4 instead.
Builds an RPUSH command to append one or more values to the tail of
the list at key. Returns the length of the list after the push.
Functions
Builds a BLPOP command to perform a blocking pop from the head of one or
more lists. The call blocks for up to timeout seconds until an element
becomes available. A timeout of 0 blocks indefinitely.
Deprecated: use blmove/5 instead.
Builds an LMOVE command to atomically pop an element from source and
push it to destination. Use wherefrom and whereto ("LEFT" or
"RIGHT") to control which end of each list is used.
@spec lpop(String.t(), non_neg_integer() | nil) :: [String.t()]
Builds an LPOP command to remove and return the first element of the list
at key. When count is provided, removes and returns up to count
elements from the head.
Builds an LPUSH command to prepend one or more values to the head of
the list at key. Elements are inserted one after another from left to
right, so the last element in the list will be the first in the resulting
list. Returns the length of the list after the push.
Builds an LRANGE command to return elements from index start to stop
(inclusive) in the list at key. Indices are 0-based; negative indices
count from the end (-1 is the last element).
@spec rpop(String.t(), non_neg_integer() | nil) :: [String.t()]
Builds an RPOP command to remove and return the last element of the list
at key. When count is provided, removes and returns up to count
elements from the tail.
Deprecated: use lmove/4 instead.
Builds an RPUSH command to append one or more values to the tail of
the list at key. Returns the length of the list after the push.