Skip to content

RedisQueueDriver

Redis-backed PollableQueueDriverInterface.

Ready jobs live in a Redis LIST ({prefix}:ready); reserve() atomically moves one into a {prefix}:processing LIST via RPOPLPUSH (the classic reliable-queue pattern) so a crashed worker’s in-flight jobs are still recoverable from that list rather than lost. Delayed/released jobs live in a ZSET ({prefix}:delayed) scored by their available_at unix timestamp; reserve() first promotes any due members back onto the ready list.

ReservedJob::$id is the exact JSON-encoded list entry (each entry embeds a random uid so two otherwise-identical jobs remain distinct strings) — driver-specific per ReservedJob’s contract, used as the LREM target in ack()/release()/discard().

final readonly class RedisQueueDriver implements PollableQueueDriverInterface

ImplementsPollableQueueDriverInterface
SourceRedisQueueDriver.php

public function __construct(ClientInterface $redis, string $prefix = 'quiote_queue', ClockInterface $clock = new SystemClock(…), RandomnessInterface $randomness = new SystemRandomness(…)): mixed

ParameterTypeDescription
$redisClientInterface
$prefixstring
$clockClockInterface
$randomnessRandomnessInterface

Returns mixed

MethodDescription
ack(ReservedJob $job): voidRemoves the job’s entry from the processing list, completing the reservation.
discard(ReservedJob $job): voidDrops the job’s entry from the processing list without re-queueing it.
push(JobPayload $payload): voidEncodes the job as a JSON entry and files it on the ready or delayed key.
release(ReservedJob $job, int $delaySeconds): voidRemoves the job from the processing list and re-files it for another run.
reserve(): ?ReservedJobPromotes any due delayed jobs, then atomically claims the next ready one.

public function ack(ReservedJob $job): void

Removes the job’s entry from the processing list, completing the reservation.

ParameterTypeDescription
$jobReservedJob

public function discard(ReservedJob $job): void

Drops the job’s entry from the processing list without re-queueing it.

Called once retries are exhausted; the dead-letter record has already been written by JobExecutor.

ParameterTypeDescription
$jobReservedJob

public function push(JobPayload $payload): void

Encodes the job as a JSON entry and files it on the ready or delayed key.

A job that is already due is LPUSHed onto {prefix}:ready; one with a future JobPayload::$availableAt is added to the {prefix}:delayed ZSET scored by that timestamp, from where RedisQueueDriver::reserve() promotes it once due. The entry carries a fresh random uid so two identical jobs stay distinguishable as list members.

ParameterTypeDescription
$payloadJobPayload
ThrowsWhen
JsonExceptionif the payload params cannot be encoded.

public function release(ReservedJob $job, int $delaySeconds): void

Removes the job from the processing list and re-files it for another run.

The re-filed entry keeps the original uid but carries an incremented attempt count, and goes onto the ready list when the delay is zero or negative, otherwise onto the delayed ZSET.

ParameterTypeDescription
$jobReservedJob
$delaySecondsint
ThrowsWhen
JsonExceptionif the payload params cannot be re-encoded.

public function reserve(): ?ReservedJob

Promotes any due delayed jobs, then atomically claims the next ready one.

The claim is a single RPOPLPUSH from {prefix}:ready to {prefix}:processing, so a job is never in neither list. Returns null when the ready list is empty after promotion.

Returns ?ReservedJob

ThrowsWhen
RuntimeExceptionif the claimed entry is not a JSON object or its job_class/params/attempts fields have the wrong type.
JsonExceptionif the claimed entry is not valid JSON.