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.
Error Handling
Two distinct failure modes:
1. **Command-level Redis errors** (WRONGTYPE, OOM): Captured inline in result array. Pipeline continues. Check each slot for Error objects.
2. **Transport failures** (connection loss, timeout): Entire pipeline fails. Cannot determine which commands succeeded.
METHODS
new
my $pipe = Async::Redis::Pipeline->new(
redis => $redis_client,
max_depth => 10000,
);
Create a new pipeline. Usually called via $redis->pipeline.
command
$pipe->command('SET', 'key', 'value');
Queue a command explicitly.
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.