class ConcurrencyLimiter

Properties

protected list<string> $slots

Precomputed slot names. Built once in the constructor.

protected string $keyPrefix

The slot key prefix.

Methods

__construct(RedisProxy $redis, string $name, int $maxLocks, int $releaseAfter)

Create a new concurrency limiter instance.

acquire(int $timeout, int $sleep = 250)

Acquire a lease on one of the limiter's slots, waiting up to the given timeout.

mixed
block(int $timeout, callable|null $callback = null, int $sleep = 250)

Attempt to acquire the lock for the given number of seconds.

false|string
claimSlot(string $id)

Attempt to claim a free slot.

Details

at line 39
__construct(RedisProxy $redis, string $name, int $maxLocks, int $releaseAfter)

Create a new concurrency limiter instance.

Parameters

RedisProxy $redis

the Redis connection instance

string $name

the name of the limiter

int $maxLocks

the allowed number of concurrent tasks

int $releaseAfter

the number of seconds a slot should be maintained

at line 61
ConcurrencyLease acquire(int $timeout, int $sleep = 250)

Acquire a lease on one of the limiter's slots, waiting up to the given timeout.

Parameters

int $timeout
int $sleep

Return Value

ConcurrencyLease

Exceptions

LimiterTimeoutException

at line 92
mixed block(int $timeout, callable|null $callback = null, int $sleep = 250)

Attempt to acquire the lock for the given number of seconds.

When no callback is given, the slot is reserved fire-and-forget: it is held until the releaseAfter TTL reclaims it. Use acquire() to obtain a releasable lease instead.

Parameters

int $timeout
callable|null $callback
int $sleep

Return Value

mixed

Exceptions

LimiterTimeoutException
Throwable

at line 128
protected false|string claimSlot(string $id)

Attempt to claim a free slot.

Parameters

string $id

a unique identifier for this lease

Return Value

false|string