NAME
Async::Redis::Pool - Connection pool for Async::Redis
SYNOPSIS
my $pool = Async::Redis::Pool->new(
host => 'localhost',
min => 2,
max => 10,
);
# Recommended: scoped pattern
my $result = await $pool->with(async sub {
my ($redis) = @_;
await $redis->incr('counter');
});
# Manual acquire/release (be careful!)
my $redis = await $pool->acquire;
await $redis->set('key', 'value');
$pool->release($redis);
DESCRIPTION
Manages a pool of Redis connections with automatic dirty detection.
Connection Cleanliness
A connection is "dirty" if it has state that could affect the next user:
in_multi - In a MULTI transaction
watching - Has WATCH keys
in_pubsub - In subscription mode
inflight - Has pending responses
Dirty connections are destroyed by default. The cost of a new TCP handshake is far less than the risk of data corruption.
The with() Pattern
Always prefer with() over manual acquire/release:
await $pool->with(async sub {
my ($redis) = @_;
# Use $redis here
# Connection released automatically, even on exception
});