NAME

Async::Redis::Subscription - PubSub subscription handler

SYNOPSIS

my $sub = await $redis->subscribe('channel1', 'channel2');

while (my $msg = await $sub->next) {
    say "Channel: $msg->{channel}";
    say "Data: $msg->{data}";
}

await $sub->unsubscribe('channel1');
await $sub->unsubscribe;  # all remaining

DESCRIPTION

Manages Redis PubSub subscriptions with async iterator pattern.

MESSAGE STRUCTURE

{
    type    => 'message',      # or 'pmessage', 'smessage'
    channel => 'channel_name',
    pattern => 'pattern',      # only for pmessage
    data    => 'payload',
}

next() always returns real pub/sub messages. Reconnection is transparent.

RECONNECTION

When reconnect is enabled on the Redis connection, subscriptions are automatically re-established after a connection drop. To be notified:

$sub->on_reconnect(sub {
    my ($sub) = @_;
    warn "Reconnected, may have lost messages";
    # re-poll state, log, etc.
});

Messages published while the connection was down are lost (Redis pub/sub has no persistence).