class AthenaRatelimitBucket implements RatelimitBucketInterface (View source)

Manages a route's ratelimit in Redis, using Athena. Requires client option http.ratelimitbucket.athena to be set to an instance of AthenaCache.

Requires the suggested package charlottedunois/athena.

Properties

protected APIManager $api The API manager.
protected string $endpoint The endpoint.
protected APIRequest[] $queue The request queue.
protected AthenaCache $cache The athena cache instance.
protected bool $busy Whether the bucket is busy.

Methods

__construct(APIManager $api, string $endpoint)

DO NOT initialize this class yourself.

__destruct()

Destroys the bucket.

bool
isBusy()

Whether we are busy.

void
setBusy(bool $busy)

Sets the busy flag (marking as running).

ExtendedPromiseInterface|void
handleRatelimit(int|null $limit, int|null $remaining, float|null $resetTime)

Sets the ratelimits from the response

string
getEndpoint()

Returns the endpoint this bucket is for.

int
size()

Returns the size of the queue

$this
push(APIRequest $request)

Pushes a new request into the queue.

$this
unshift(APIRequest $request)

Unshifts a new request into the queue. Modifies remaining ratelimit.

ExtendedPromiseInterface|array
getMeta()

Retrieves ratelimit meta data.

APIRequest|false
shift()

Returns the first queue item or false. Modifies remaining ratelimit.

void
clear()

Unsets all queue items.

ExtendedPromiseInterface
get()

Retrieves the cache data.

ExtendedPromiseInterface
set(array $value)

Sets the cache data.

Details

__construct(APIManager $api, string $endpoint)

DO NOT initialize this class yourself.

Parameters

APIManager $api
string $endpoint

Exceptions

RuntimeException

__destruct()

Destroys the bucket.

bool isBusy()

Whether we are busy.

Return Value

bool

void setBusy(bool $busy)

Sets the busy flag (marking as running).

Parameters

bool $busy

Return Value

void

ExtendedPromiseInterface|void handleRatelimit(int|null $limit, int|null $remaining, float|null $resetTime)

Sets the ratelimits from the response

Parameters

int|null $limit
int|null $remaining
float|null $resetTime Reset time in seconds with milliseconds.

Return Value

ExtendedPromiseInterface|void

string getEndpoint()

Returns the endpoint this bucket is for.

Return Value

string

int size()

Returns the size of the queue

Return Value

int

$this push(APIRequest $request)

Pushes a new request into the queue.

Parameters

APIRequest $request

Return Value

$this

$this unshift(APIRequest $request)

Unshifts a new request into the queue. Modifies remaining ratelimit.

Parameters

APIRequest $request

Return Value

$this

ExtendedPromiseInterface|array getMeta()

Retrieves ratelimit meta data.

The resolved value must be:

array(
    'limited' => bool,
    'resetTime' => int|null
)

Return Value

ExtendedPromiseInterface|array

APIRequest|false shift()

Returns the first queue item or false. Modifies remaining ratelimit.

Return Value

APIRequest|false

void clear()

Unsets all queue items.

Return Value

void

protected ExtendedPromiseInterface get()

Retrieves the cache data.

Return Value

ExtendedPromiseInterface

protected ExtendedPromiseInterface set(array $value)

Sets the cache data.

Parameters

array $value

Return Value

ExtendedPromiseInterface