class DurationLimiterBuilder

Traits

Properties

int $maxLocks

The maximum number of locks that can be obtained per time window.

int $decay

The amount of time the lock window is maintained.

int $timeout

The amount of time to block until a lock is available.

int $sleep

The number of milliseconds to wait between attempts to acquire the lock.

Methods

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

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

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $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.

__construct(RedisProxy $connection, string $name)

Create a new builder instance.

allow(int $maxLocks)

Set the maximum number of locks that can be obtained per time window.

every(DateTimeInterface|DateInterval|int $decay)

Set the amount of time the lock window is maintained.

block(int $timeout)

Set the amount of time to block until a lock is available.

sleep(int $sleep)

Set the number of milliseconds to wait between lock acquisition attempts.

mixed
then(callable $callback, callable|null $failure = null)

Execute the given callback if a lock is obtained, otherwise call the failure callback.

Details

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 41
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

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

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 57
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 65
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

at line 43
__construct(RedisProxy $connection, string $name)

Create a new builder instance.

Parameters

RedisProxy $connection

the Redis connection instance

string $name

the name of the lock

at line 52
DurationLimiterBuilder allow(int $maxLocks)

Set the maximum number of locks that can be obtained per time window.

Parameters

int $maxLocks

Return Value

DurationLimiterBuilder

at line 62
DurationLimiterBuilder every(DateTimeInterface|DateInterval|int $decay)

Set the amount of time the lock window is maintained.

Parameters

DateTimeInterface|DateInterval|int $decay

Return Value

DurationLimiterBuilder

at line 72
DurationLimiterBuilder block(int $timeout)

Set the amount of time to block until a lock is available.

Parameters

int $timeout

Return Value

DurationLimiterBuilder

at line 82
DurationLimiterBuilder sleep(int $sleep)

Set the number of milliseconds to wait between lock acquisition attempts.

Parameters

int $sleep

Return Value

DurationLimiterBuilder

at line 94
mixed then(callable $callback, callable|null $failure = null)

Execute the given callback if a lock is obtained, otherwise call the failure callback.

Parameters

callable $callback
callable|null $failure

Return Value

mixed

Exceptions

LimiterTimeoutException