class DurationLimiterBuilder (View source)

Traits

Properties

Connection $connection

The Redis connection.

string $name

The name of the lock.

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(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.

void
__construct(Connection $connection, string $name)

Create a new builder instance.

$this
allow(int $maxLocks)

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

$this
every(DateTimeInterface|DateInterval|int $decay)

Set the amount of time the lock window is maintained.

$this
block(int $timeout)

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

$this
sleep(int $sleep)

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

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

void __construct(Connection $connection, string $name)

Create a new builder instance.

Parameters

Connection $connection
string $name

Return Value

void

$this allow(int $maxLocks)

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

Parameters

int $maxLocks

Return Value

$this

$this every(DateTimeInterface|DateInterval|int $decay)

Set the amount of time the lock window is maintained.

Parameters

DateTimeInterface|DateInterval|int $decay

Return Value

$this

$this block(int $timeout)

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

Parameters

int $timeout

Return Value

$this

$this sleep(int $sleep)

The number of milliseconds to wait between lock acquisition attempts.

Parameters

int $sleep

Return Value

$this

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