class RedisQueue extends Queue implements Queue, ClearableQueue (View source)

Traits

Properties

protected Container $container

The IoC container instance.

from  Queue
protected string $connectionName

The connection name for the queue.

from  Queue
protected array $config

The original configuration for the queue.

from  Queue
protected bool $dispatchAfterCommit

Indicates that jobs should be dispatched after all database transactions have committed.

from  Queue
static protected callable[] $createPayloadCallbacks

The create payload callbacks.

from  Queue
protected Factory $redis

The Redis factory implementation.

protected string $connection

The connection name.

protected string $default

The name of the default queue.

protected int|null $retryAfter

The expiration time of a job.

protected int|null $blockFor

The maximum number of seconds to block for a job.

protected int $migrationBatchSize

The batch size to use when migrating delayed / expired jobs onto the primary queue.

protected bool $secondaryQueueHadJob

Indicates if a secondary queue had a job available between checks of the primary queue.

protected bool|null $isCluster

Indicates if the connection is a Redis Cluster connection.

Methods

int
secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateTimeInterface|DateInterval|int $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateTimeInterface|DateInterval|int $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

mixed
getAttributeValue(object $target, string $attributeClass, string|null $property = null, mixed $default = null)

Get a configuration value from an attribute, falling back to a property.

mixed
extractAttributeValue(object $instance)

Extract the value from an attribute instance.

object|null
getAttributeInstance(object $target, string $attributeClass)

Get an instance of the given attribute class from the target class or its parents.

mixed
pushOn(string $queue, string $job, mixed $data = '')

Push a new job onto the queue.

from  Queue
mixed
laterOn(string $queue, DateTimeInterface|DateInterval|int $delay, string $job, mixed $data = '')

Push a new job onto a specific queue after (n) seconds.

from  Queue
void
bulk(array $jobs, mixed $data = '', string|null $queue = null)

Push an array of jobs onto the queue.

string
createPayload(Closure|string|object $job, string $queue, mixed $data = '', DateTimeInterface|DateInterval|int|null $delay = null)

Create a payload string from the given job and data.

from  Queue
array
createPayloadArray(string|object $job, string $queue, mixed $data = '')

Create a payload string from the given job and data.

array
createObjectPayload(object $job, string $queue)

Create a payload for an object-based queue handler.

from  Queue
string
getDisplayName(object $job)

Get the display name for the given job.

from  Queue
mixed
getJobTries(mixed $job)

Get the maximum number of attempts for an object-based queue handler.

from  Queue
mixed
getJobBackoff(mixed $job)

Get the backoff for an object-based queue handler.

from  Queue
mixed
getJobExpiration(mixed $job)

Get the expiration timestamp for an object-based queue handler.

from  Queue
bool
jobShouldBeEncrypted(object $job)

Determine if the job should be encrypted.

from  Queue
array
createStringPayload(string $job, string $queue, mixed $data)

Create a typical, string based queue payload array.

from  Queue
static void
createPayloadUsing(callable|null $callback)

Register a callback to be executed when creating job payloads.

from  Queue
array
withCreatePayloadHooks(string $queue, array $payload)

Create the given payload using any registered payload hooks.

from  Queue
mixed
enqueueUsing(Closure|string|object $job, string $payload, string|null $queue, DateTimeInterface|DateInterval|int|null $delay, callable $callback)

Enqueue a job using the given callback.

from  Queue
bool
shouldDispatchAfterCommit(Closure|string|object $job)

Determine if the job should be dispatched after all database transactions have committed.

from  Queue
void
raiseJobQueueingEvent(string $queue, Closure|string|object $job, string $payload, DateTimeInterface|DateInterval|int|null $delay)

Raise the job queueing event.

from  Queue
void
raiseJobQueuedEvent(string|null $queue, string|int|null $jobId, Closure|string|object $job, string $payload, DateTimeInterface|DateInterval|int|null $delay)

Raise the job queued event.

from  Queue
string
getConnectionName()

Get the connection name for the queue.

from  Queue
$this
setConnectionName(string $name)

Set the connection name for the queue.

from  Queue
array
getConfig()

Get the queue configuration array.

from  Queue
$this
setConfig(array $config)

Set the queue configuration array.

from  Queue
getContainer()

Get the container instance being used by the connection.

from  Queue
void
setContainer(Container $container)

Set the IoC container instance.

from  Queue
__construct(Factory $redis, string $default = 'default', string|null $connection = null, int $retryAfter = 60, int|null $blockFor = null, bool $dispatchAfterCommit = false, int $migrationBatchSize = -1)

Create a new Redis queue instance.

int
size(string|null $queue = null)

Get the size of the queue.

int
pendingSize(string|null $queue = null)

Get the number of pending jobs.

int
delayedSize(string|null $queue = null)

Get the number of delayed jobs.

int
reservedSize(string|null $queue = null)

Get the number of reserved jobs.

pendingJobs(string|null $queue = null)

Get the pending jobs for the given queue.

delayedJobs(string|null $queue = null)

Get the delayed jobs for the given queue.

reservedJobs(string|null $queue = null)

Get the reserved jobs for the given queue.

allPendingJobs()

Get all pending jobs across every queue.

allDelayedJobs()

Get all delayed jobs across every queue.

allReservedJobs()

Get all reserved jobs across every queue.

allQueueNames()

Get the unique queue names.

int|null
creationTimeOfOldestPendingJob(string|null $queue = null)

Get the creation timestamp of the oldest pending job, excluding delayed jobs.

mixed
push(string|object $job, mixed $data = '', string|null $queue = null)

Push a new job onto the queue.

mixed
pushRaw(string $payload, string|null $queue = null, array $options = [])

Push a raw payload onto the queue.

mixed
later(DateTimeInterface|DateInterval|int $delay, string|object $job, mixed $data = '', string|null $queue = null)

Push a new job onto the queue after a delay.

mixed
laterRaw(DateTimeInterface|DateInterval|int $delay, string $payload, string|null $queue = null)

Push a raw job onto the queue after (n) seconds.

Job|null
pop(string|null $queue = null, int $index = 0)

Pop the next job off of the queue.

void
migrate(string $queue)

Migrate any delayed or expired jobs onto the primary queue.

array
migrateExpiredJobs(string $from, string $to)

Migrate the delayed jobs that are ready to the regular queue.

array
retrieveNextJob(string $queue, bool $block = true)

Retrieve the next job from the queue.

void
deleteReserved(string $queue, RedisJob $job)

Delete a reserved job from the queue.

void
deleteAndRelease(string $queue, RedisJob $job, int $delay)

Delete a reserved job from the reserved queue and release it.

int
clear(string $queue)

Delete all of the jobs from the queue.

string
getRandomId()

Get a random ID string.

string
getQueue(string|null $queue)

Get the queue or return the default.

string
getQueueRedisKey(string|null $queue = null)

Get the cluster-safe Redis key for the given queue.

getConnection()

Get the connection for the queue.

bool
isClusterConnection()

Determine if the connection is a Redis Cluster connection.

getRedis()

Get the underlying Redis instance.

Details

protected int secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

protected int availableAt(DateTimeInterface|DateInterval|int $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

protected DateTimeInterface|int parseDateInterval(DateTimeInterface|DateInterval|int $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

DateTimeInterface|int

protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

protected string runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float|null $endTime

Return Value

string

protected mixed getAttributeValue(object $target, string $attributeClass, string|null $property = null, mixed $default = null)

Get a configuration value from an attribute, falling back to a property.

Parameters

object $target
string $attributeClass
string|null $property
mixed $default

Return Value

mixed

protected mixed extractAttributeValue(object $instance)

Extract the value from an attribute instance.

Parameters

object $instance

Return Value

mixed

protected object|null getAttributeInstance(object $target, string $attributeClass)

Get an instance of the given attribute class from the target class or its parents.

Parameters

object $target
string $attributeClass

Return Value

object|null

mixed pushOn(string $queue, string $job, mixed $data = '')

Push a new job onto the queue.

Parameters

string $queue
string $job
mixed $data

Return Value

mixed

mixed laterOn(string $queue, DateTimeInterface|DateInterval|int $delay, string $job, mixed $data = '')

Push a new job onto a specific queue after (n) seconds.

Parameters

string $queue
DateTimeInterface|DateInterval|int $delay
string $job
mixed $data

Return Value

mixed

void bulk(array $jobs, mixed $data = '', string|null $queue = null)

Push an array of jobs onto the queue.

Parameters

array $jobs
mixed $data
string|null $queue

Return Value

void

protected string createPayload(Closure|string|object $job, string $queue, mixed $data = '', DateTimeInterface|DateInterval|int|null $delay = null)

Create a payload string from the given job and data.

Parameters

Closure|string|object $job
string $queue
mixed $data
DateTimeInterface|DateInterval|int|null $delay

Return Value

string

Exceptions

InvalidPayloadException

protected array createPayloadArray(string|object $job, string $queue, mixed $data = '')

Create a payload string from the given job and data.

Parameters

string|object $job
string $queue
mixed $data

Return Value

array

protected array createObjectPayload(object $job, string $queue)

Create a payload for an object-based queue handler.

Parameters

object $job
string $queue

Return Value

array

Exceptions

RuntimeException

protected string getDisplayName(object $job)

Get the display name for the given job.

Parameters

object $job

Return Value

string

mixed getJobTries(mixed $job)

Get the maximum number of attempts for an object-based queue handler.

Parameters

mixed $job

Return Value

mixed

mixed getJobBackoff(mixed $job)

Get the backoff for an object-based queue handler.

Parameters

mixed $job

Return Value

mixed

mixed getJobExpiration(mixed $job)

Get the expiration timestamp for an object-based queue handler.

Parameters

mixed $job

Return Value

mixed

protected bool jobShouldBeEncrypted(object $job)

Determine if the job should be encrypted.

Parameters

object $job

Return Value

bool

protected array createStringPayload(string $job, string $queue, mixed $data)

Create a typical, string based queue payload array.

Parameters

string $job
string $queue
mixed $data

Return Value

array

static void createPayloadUsing(callable|null $callback)

Register a callback to be executed when creating job payloads.

Parameters

callable|null $callback

Return Value

void

protected array withCreatePayloadHooks(string $queue, array $payload)

Create the given payload using any registered payload hooks.

Parameters

string $queue
array $payload

Return Value

array

protected mixed enqueueUsing(Closure|string|object $job, string $payload, string|null $queue, DateTimeInterface|DateInterval|int|null $delay, callable $callback)

Enqueue a job using the given callback.

Parameters

Closure|string|object $job
string $payload
string|null $queue
DateTimeInterface|DateInterval|int|null $delay
callable $callback

Return Value

mixed

protected bool shouldDispatchAfterCommit(Closure|string|object $job)

Determine if the job should be dispatched after all database transactions have committed.

Parameters

Closure|string|object $job

Return Value

bool

protected void raiseJobQueueingEvent(string $queue, Closure|string|object $job, string $payload, DateTimeInterface|DateInterval|int|null $delay)

Raise the job queueing event.

Parameters

string $queue
Closure|string|object $job
string $payload
DateTimeInterface|DateInterval|int|null $delay

Return Value

void

protected void raiseJobQueuedEvent(string|null $queue, string|int|null $jobId, Closure|string|object $job, string $payload, DateTimeInterface|DateInterval|int|null $delay)

Raise the job queued event.

Parameters

string|null $queue
string|int|null $jobId
Closure|string|object $job
string $payload
DateTimeInterface|DateInterval|int|null $delay

Return Value

void

string getConnectionName()

Get the connection name for the queue.

Return Value

string

$this setConnectionName(string $name)

Set the connection name for the queue.

Parameters

string $name

Return Value

$this

array getConfig()

Get the queue configuration array.

Return Value

array

$this setConfig(array $config)

Set the queue configuration array.

Parameters

array $config

Return Value

$this

Container getContainer()

Get the container instance being used by the connection.

Return Value

Container

void setContainer(Container $container)

Set the IoC container instance.

Parameters

Container $container

Return Value

void

__construct(Factory $redis, string $default = 'default', string|null $connection = null, int $retryAfter = 60, int|null $blockFor = null, bool $dispatchAfterCommit = false, int $migrationBatchSize = -1)

Create a new Redis queue instance.

Parameters

Factory $redis
string $default
string|null $connection
int $retryAfter
int|null $blockFor
bool $dispatchAfterCommit
int $migrationBatchSize

int size(string|null $queue = null)

Get the size of the queue.

Parameters

string|null $queue

Return Value

int

int pendingSize(string|null $queue = null)

Get the number of pending jobs.

Parameters

string|null $queue

Return Value

int

int delayedSize(string|null $queue = null)

Get the number of delayed jobs.

Parameters

string|null $queue

Return Value

int

int reservedSize(string|null $queue = null)

Get the number of reserved jobs.

Parameters

string|null $queue

Return Value

int

Collection pendingJobs(string|null $queue = null)

Get the pending jobs for the given queue.

Parameters

string|null $queue

Return Value

Collection

Collection delayedJobs(string|null $queue = null)

Get the delayed jobs for the given queue.

Parameters

string|null $queue

Return Value

Collection

Collection reservedJobs(string|null $queue = null)

Get the reserved jobs for the given queue.

Parameters

string|null $queue

Return Value

Collection

Collection allPendingJobs()

Get all pending jobs across every queue.

Return Value

Collection

Collection allDelayedJobs()

Get all delayed jobs across every queue.

Return Value

Collection

Collection allReservedJobs()

Get all reserved jobs across every queue.

Return Value

Collection

protected Collection allQueueNames()

Get the unique queue names.

Return Value

Collection

int|null creationTimeOfOldestPendingJob(string|null $queue = null)

Get the creation timestamp of the oldest pending job, excluding delayed jobs.

Parameters

string|null $queue

Return Value

int|null

mixed push(string|object $job, mixed $data = '', string|null $queue = null)

Push a new job onto the queue.

Parameters

string|object $job
mixed $data
string|null $queue

Return Value

mixed

mixed pushRaw(string $payload, string|null $queue = null, array $options = [])

Push a raw payload onto the queue.

Parameters

string $payload
string|null $queue
array $options

Return Value

mixed

mixed later(DateTimeInterface|DateInterval|int $delay, string|object $job, mixed $data = '', string|null $queue = null)

Push a new job onto the queue after a delay.

Parameters

DateTimeInterface|DateInterval|int $delay
string|object $job
mixed $data
string|null $queue

Return Value

mixed

protected mixed laterRaw(DateTimeInterface|DateInterval|int $delay, string $payload, string|null $queue = null)

Push a raw job onto the queue after (n) seconds.

Parameters

DateTimeInterface|DateInterval|int $delay
string $payload
string|null $queue

Return Value

mixed

Job|null pop(string|null $queue = null, int $index = 0)

Pop the next job off of the queue.

Parameters

string|null $queue
int $index

Return Value

Job|null

protected void migrate(string $queue)

Migrate any delayed or expired jobs onto the primary queue.

Parameters

string $queue

Return Value

void

array migrateExpiredJobs(string $from, string $to)

Migrate the delayed jobs that are ready to the regular queue.

Parameters

string $from
string $to

Return Value

array

protected array retrieveNextJob(string $queue, bool $block = true)

Retrieve the next job from the queue.

Parameters

string $queue
bool $block

Return Value

array

void deleteReserved(string $queue, RedisJob $job)

Delete a reserved job from the queue.

Parameters

string $queue
RedisJob $job

Return Value

void

void deleteAndRelease(string $queue, RedisJob $job, int $delay)

Delete a reserved job from the reserved queue and release it.

Parameters

string $queue
RedisJob $job
int $delay

Return Value

void

int clear(string $queue)

Delete all of the jobs from the queue.

Parameters

string $queue

Return Value

int

protected string getRandomId()

Get a random ID string.

Return Value

string

string getQueue(string|null $queue)

Get the queue or return the default.

Parameters

string|null $queue

Return Value

string

protected string getQueueRedisKey(string|null $queue = null)

Get the cluster-safe Redis key for the given queue.

Parameters

string|null $queue

Return Value

string

Connection getConnection()

Get the connection for the queue.

Return Value

Connection

protected bool isClusterConnection()

Determine if the connection is a Redis Cluster connection.

Return Value

bool

Factory getRedis()

Get the underlying Redis instance.

Return Value

Factory