NAME

Async::Redis::AutoPipeline - Automatic command batching

DESCRIPTION

AutoPipeline transparently batches Redis commands issued in the same event loop tick into a single pipeline, reducing network round-trips without changing the caller's API.

How It Works

# These three commands are batched automatically
my $f1 = $redis->set('a', 1);
my $f2 = $redis->set('b', 2);
my $f3 = $redis->get('a');

await Future->needs_all($f1, $f2, $f3);

When auto_pipeline => 1:

  1. Commands queue locally instead of sending immediately.

  2. A next-tick flush is scheduled with Future::IO->sleep(0).

  3. When the event loop yields, queued commands flush as a pipeline.

  4. Responses are distributed to the original command futures.

Invariants

  • _flush_pending prevents double-scheduling

  • _flushing guard prevents reentrancy

  • Depth limit triggers multiple batches if exceeded

  • Future::IO->sleep(0) provides the non-blocking yield point