NAME

Async::Redis::Pipeline - Command pipelining

SYNOPSIS

my $pipe = $redis->pipeline;
$pipe->set('key1', 'value1');
$pipe->set('key2', 'value2');
$pipe->get('key1');

my $results = await $pipe->execute;
# $results = ['OK', 'OK', 'value1']

# Or chained style:
my $results = await $redis->pipeline
    ->set('a', 1)
    ->get('a')
    ->execute;

DESCRIPTION

Pipeline collects multiple Redis commands and executes them in a single network round-trip, significantly reducing latency for bulk operations. Pipeline objects are single-use; after execute, additional queued commands are rejected and another execute returns an empty result.

Error Handling

Two distinct failure modes:

  1. Command-level Redis errors (WRONGTYPE, OOM): captured inline in the result array. The pipeline continues. Check each slot for error objects.

  2. Transport failures (connection loss, timeout): the entire pipeline fails. The client cannot determine which commands succeeded on the server.

METHODS

new

my $pipe = Async::Redis::Pipeline->new(
    redis     => $redis_client,
    max_depth => 10000,
);

Create a new pipeline. Usually called via $redis->pipeline. max_depth defaults to the parent Redis object's pipeline_depth.

command

$pipe->command('SET', 'key', 'value');

Queue a command explicitly.

add

$pipe->add('SET', 'key', 'value');

Backward-compatible alias for queuing an explicit command.

AUTOLOAD

Any Redis command can be called directly:

$pipe->set('key', 'value');
$pipe->hset('hash', 'field', 'value');
$pipe->lpush('list', 'item');

execute

my $results = await $pipe->execute;

Execute all queued commands and return results array.

run_script

$pipe->run_script('my_script', @keys_then_args);

Queue a registered Lua script by name. The script must be registered via $redis->define_command() before use.

For scripts with fixed key count:

$pipe->run_script('publish_msg', 'topic:chat', $message);

For scripts with dynamic key count (first arg is key count):

$pipe->run_script('dynamic_script', 2, 'key1', 'key2', 'arg1');

Scripts are automatically preloaded before pipeline execution to ensure EVALSHA succeeds.

count

my $n = $pipe->count;

Return number of queued commands.