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 $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()

Connect to Redis and start subscribing.

void
disconnect()

Disconnect from Redis.

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
reconnect()

Attempt to reconnect to Redis.

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 45
__construct(PubSubIncomingMessageHandler $messageHandler, RedisProxy $redis, string $channel)

Create a new Redis pub/sub provider instance.

Parameters

PubSubIncomingMessageHandler $messageHandler
RedisProxy $redis
string $channel

at line 58
void connect()

Connect to Redis and start subscribing.

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

Return Value

void

at line 101
void disconnect()

Disconnect from Redis.

Return Value

void

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

Process messages from one committed subscriber.

Parameters

Subscriber $subscriber
string $subscribedChannel

Return Value

void

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

Listen for a given event type.

Parameters

string $event
callable $callback

Return Value

void

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

Listen for the given event.

Parameters

string $event
callable $callback

Return Value

void

at line 167
void stopListening(string $event)

Stop listening for the given event.

Parameters

string $event

Return Value

void

at line 175
int publish(array $payload)

Publish a payload to the Redis channel.

Parameters

array $payload

Return Value

int

Number of subscribers that received the message

at line 183
protected void reconnect()

Attempt to reconnect to Redis.

Return Value

void

at line 216
protected bool shouldRetry()

Determine whether reconnect work remains enabled.

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

Return Value

bool

at line 224
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 237
protected void closeSubscriber(Subscriber|null $subscriber)

Close an owned subscriber without replacing the primary lifecycle failure.

Parameters

Subscriber|null $subscriber

Return Value

void