class ThrottlesExceptionsWithRedis extends ThrottlesExceptions (View source)

Traits

Properties

protected string $key

The developer specified key that the rate limiter should use.

from  ThrottlesExceptions
protected bool $byJob

Indicates whether the throttle key should use the job's UUID.

from  ThrottlesExceptions
protected int $maxAttempts

The maximum number of attempts allowed before rate limiting applies.

from  ThrottlesExceptions
protected int $decaySeconds

The number of seconds until the maximum attempts are reset.

from  ThrottlesExceptions
protected int $retryAfterMinutes

The number of minutes to wait before retrying the job after an exception.

from  ThrottlesExceptions
protected callable $reportCallback

The callback that determines if the exception should be reported.

from  ThrottlesExceptions
protected callable $whenCallback

The callback that determines if rate limiting should apply.

from  ThrottlesExceptions
protected string $prefix

The prefix of the rate limiter key.

from  ThrottlesExceptions
protected DurationLimiter $limiter

The rate limiter instance.

protected Factory $redis

The Redis factory implementation.

Methods

void
__construct(int $maxAttempts = 10, int $decaySeconds = 600)

Create a new middleware instance.

mixed
handle(mixed $job, callable $next)

Process the job.

$this
when(callable $callback)

Specify a callback that should determine if rate limiting behavior should apply.

$this
withPrefix(string $prefix)

Set the prefix of the rate limiter key.

$this
backoff(int $backoff)

Specify the number of minutes a job should be delayed when it is released (before it has reached its max exceptions).

string
getKey(mixed $job)

Get the cache key associated for the rate limiter.

$this
by(string $key)

Set the value that the rate limiter should be keyed by.

$this
byJob()

Indicate that the throttle key should use the job's UUID.

$this
report(callable|null $callback = null)

Report exceptions and optionally specify a callback that determines if the exception should be reported.

int
getTimeUntilNextRetry(string $key)

Get the number of seconds that should elapse before the job is retried.

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 $endTime = null)

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

Details

void __construct(int $maxAttempts = 10, int $decaySeconds = 600)

Create a new middleware instance.

Parameters

int $maxAttempts
int $decaySeconds

Return Value

void

mixed handle(mixed $job, callable $next)

Process the job.

Parameters

mixed $job
callable $next

Return Value

mixed

$this when(callable $callback)

Specify a callback that should determine if rate limiting behavior should apply.

Parameters

callable $callback

Return Value

$this

$this withPrefix(string $prefix)

Set the prefix of the rate limiter key.

Parameters

string $prefix

Return Value

$this

$this backoff(int $backoff)

Specify the number of minutes a job should be delayed when it is released (before it has reached its max exceptions).

Parameters

int $backoff

Return Value

$this

protected string getKey(mixed $job)

Get the cache key associated for the rate limiter.

Parameters

mixed $job

Return Value

string

$this by(string $key)

Set the value that the rate limiter should be keyed by.

Parameters

string $key

Return Value

$this

$this byJob()

Indicate that the throttle key should use the job's UUID.

Return Value

$this

$this report(callable|null $callback = null)

Report exceptions and optionally specify a callback that determines if the exception should be reported.

Parameters

callable|null $callback

Return Value

$this

protected int getTimeUntilNextRetry(string $key)

Get the number of seconds that should elapse before the job is retried.

Parameters

string $key

Return Value

int

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 $endTime = null)

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

Parameters

float $startTime
float $endTime

Return Value

string

Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.