Documentation

DurationLimiter
in package

Table of Contents

$decaysAt  : int
The timestamp of the end of the current duration.
$remaining  : int
The number of remaining slots.
$decay  : int
The number of seconds a slot should be maintained.
$maxLocks  : int
The allowed number of concurrent tasks.
$name  : string
The unique name of the lock.
$redis  : Connection
The Redis factory implementation.
__construct()  : void
Create a new duration limiter instance.
acquire()  : bool
Attempt to acquire the lock.
block()  : bool
Attempt to acquire the lock for the given number of seconds.
luaScript()  : string
Get the Lua script for acquiring a lock.

Properties

$decaysAt

The timestamp of the end of the current duration.

public int $decaysAt

$decay

The number of seconds a slot should be maintained.

private int $decay

$maxLocks

The allowed number of concurrent tasks.

private int $maxLocks

Methods

__construct()

Create a new duration limiter instance.

public __construct(Connection $redis, string $name, int $maxLocks, int $decay) : void
Parameters
$redis : Connection
$name : string
$maxLocks : int
$decay : int
Return values
void

acquire()

Attempt to acquire the lock.

public acquire() : bool
Return values
bool

block()

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

public block(int $timeout[, callable|null $callback = null ]) : bool
Parameters
$timeout : int
$callback : callable|null = null
Tags
throws
LimiterTimeoutException
Return values
bool

luaScript()

Get the Lua script for acquiring a lock.

protected luaScript() : string

KEYS[1] - The limiter name ARGV[1] - Current time in microseconds ARGV[2] - Current time in seconds ARGV[3] - Duration of the bucket ARGV[4] - Allowed number of tasks

Return values
string

Search results