class RedisPubSubProvider implements PubSubProvider

Properties

protected Subscriber|null $subscriber

The Redis subscriber instance.

protected string $subscribedChannel

The actual Redis channel name (with prefix applied).

protected bool $running

Whether the subscriber lifecycle coroutine is running.

protected bool $shouldRetry

Whether the provider should attempt to reconnect.

protected int $retryTimer

The number of seconds elapsed since attempting to reconnect.

Methods

__construct(PubSubIncomingMessageHandler $messageHandler, RedisProxy $redis, string $channel)

Create a new Redis pub/sub provider instance.

void
connect()

Start the Redis subscriber lifecycle.

void
disconnect()

Disconnect from Redis.

void
runSubscriberLifecycle()

Own subscriber construction, consumption, cleanup, and retry.

void
consumeMessages(Subscriber $subscriber, string $subscribedChannel)

Process messages from one committed subscriber.

void
on(string $event, callable $callback)

Listen for a given event type.

void
listen(string $event, callable $callback)

Listen for the given event.

void
stopListening(string $event)

Stop listening for the given event.

int
publish(array $payload)

Publish a payload to the Redis channel.

void
reportConnectionFailure(Throwable $exception)

Report a connection failure without flooding logs during an outage.

bool
waitBeforeRetry()

Wait before attempting another connection.

bool
shouldRetry()

Determine whether reconnect work remains enabled.

void
clearSubscriber(Subscriber|null $subscriber)

Clear committed state only when it still belongs to the given subscriber.

void
closeSubscriber(Subscriber|null $subscriber)

Close an owned subscriber without replacing the primary lifecycle failure.

Details

at line 52
__construct(PubSubIncomingMessageHandler $messageHandler, RedisProxy $redis, string $channel)

Create a new Redis pub/sub provider instance.

Parameters

PubSubIncomingMessageHandler $messageHandler
RedisProxy $redis
string $channel

at line 65
void connect()

Start the Redis subscriber lifecycle.

Uses the injected Redis connection's subscriber() factory so the dedicated subscriber inherits its topology, credentials, and prefix.

Return Value

void

at line 98
void disconnect()

Disconnect from Redis.

Return Value

void

at line 109
protected void runSubscriberLifecycle()

Own subscriber construction, consumption, cleanup, and retry.

Return Value

void

at line 146
protected void consumeMessages(Subscriber $subscriber, string $subscribedChannel)

Process messages from one committed subscriber.

Parameters

Subscriber $subscriber
string $subscribedChannel

Return Value

void

at line 172
void on(string $event, callable $callback)

Listen for a given event type.

Parameters

string $event
callable $callback

Return Value

void

at line 180
void listen(string $event, callable $callback)

Listen for the given event.

Parameters

string $event
callable $callback

Return Value

void

at line 188
void stopListening(string $event)

Stop listening for the given event.

Parameters

string $event

Return Value

void

at line 196
int publish(array $payload)

Publish a payload to the Redis channel.

Parameters

array $payload

Return Value

int

Subscriber count reported by Redis for the published channel

at line 204
protected void reportConnectionFailure(Throwable $exception)

Report a connection failure without flooding logs during an outage.

Parameters

Throwable $exception

Return Value

void

at line 216
protected bool waitBeforeRetry()

Wait before attempting another connection.

Return Value

bool

at line 229
protected bool shouldRetry()

Determine whether reconnect work remains enabled.

Hooked Redis I/O and coordinator waits may yield while disconnect() changes this state.

Return Value

bool

at line 237
protected void clearSubscriber(Subscriber|null $subscriber)

Clear committed state only when it still belongs to the given subscriber.

Parameters

Subscriber|null $subscriber

Return Value

void

at line 250
protected void closeSubscriber(Subscriber|null $subscriber)

Close an owned subscriber without replacing the primary lifecycle failure.

Parameters

Subscriber|null $subscriber

Return Value

void