Redis.Commands.List (Redis v0.8.0)

Copy Markdown View Source

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

blmove(source, destination, wherefrom, whereto, timeout)

@spec blmove(String.t(), String.t(), String.t(), String.t(), integer()) :: [
  String.t()
]

blmpop(timeout, numkeys, keys, direction, opts \\ [])

@spec blmpop(integer(), integer(), [String.t()], String.t(), keyword()) :: [
  String.t()
]

blpop(keys, timeout)

@spec blpop([String.t()], integer()) :: [String.t()]

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.

brpop(keys, timeout)

@spec brpop([String.t()], integer()) :: [String.t()]

brpoplpush(source, destination, timeout)

@spec brpoplpush(String.t(), String.t(), integer()) :: [String.t()]

Deprecated: use blmove/5 instead.

lindex(key, index)

@spec lindex(String.t(), integer()) :: [String.t()]

linsert(key, position, pivot, element)

@spec linsert(String.t(), :before | :after, String.t(), String.t()) :: [String.t()]

llen(key)

@spec llen(String.t()) :: [String.t()]

lmove(source, destination, wherefrom, whereto)

@spec lmove(String.t(), String.t(), String.t(), String.t()) :: [String.t()]

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.

lmpop(numkeys, keys, direction, opts \\ [])

@spec lmpop(integer(), [String.t()], String.t(), keyword()) :: [String.t()]

lpop(key, count \\ nil)

@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.

lpos(key, element, opts \\ [])

@spec lpos(String.t(), String.t(), keyword()) :: [String.t()]

lpush(key, values)

@spec lpush(String.t(), [String.t()]) :: [String.t()]

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.

lpushx(key, values)

@spec lpushx(String.t(), [String.t()]) :: [String.t()]

lrange(key, start, stop)

@spec lrange(String.t(), integer(), integer()) :: [String.t()]

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).

lrem(key, count, element)

@spec lrem(String.t(), integer(), String.t()) :: [String.t()]

lset(key, index, element)

@spec lset(String.t(), integer(), String.t()) :: [String.t()]

ltrim(key, start, stop)

@spec ltrim(String.t(), integer(), integer()) :: [String.t()]

rpop(key, count \\ nil)

@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.

rpoplpush(source, destination)

@spec rpoplpush(String.t(), String.t()) :: [String.t()]

Deprecated: use lmove/4 instead.

rpush(key, values)

@spec rpush(String.t(), [String.t()]) :: [String.t()]

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.

rpushx(key, values)

@spec rpushx(String.t(), [String.t()]) :: [String.t()]