class DurationLimiter (View source)

Properties

int $decaysAt

The timestamp of the end of the current duration.

int $remaining

The number of remaining slots.

Methods

void
__construct(Connection $redis, string $name, int $maxLocks, int $decay)

Create a new duration limiter instance.

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

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

bool
acquire()

Attempt to acquire the lock.

bool
tooManyAttempts()

Determine if the key has been "accessed" too many times.

void
clear()

Clear the limiter.

string
luaScript()

Get the Lua script for acquiring a lock.

string
tooManyAttemptsLuaScript()

Get the Lua script to determine if the key has been "accessed" too many times.

Details

void __construct(Connection $redis, string $name, int $maxLocks, int $decay)

Create a new duration limiter instance.

Parameters

Connection $redis
string $name
int $maxLocks
int $decay

Return Value

void

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

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

Parameters

int $timeout
callable|null $callback
int $sleep

Return Value

mixed

Exceptions

LimiterTimeoutException

bool acquire()

Attempt to acquire the lock.

Return Value

bool

bool tooManyAttempts()

Determine if the key has been "accessed" too many times.

Return Value

bool

void clear()

Clear the limiter.

Return Value

void

protected string luaScript()

Get the Lua script for acquiring a lock.

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 Value

string

protected string tooManyAttemptsLuaScript()

Get the Lua script to determine if the key has been "accessed" too many times.

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 Value

string