Neuron-PHP

RedisRateLimitStorage implements IRateLimitStorage

Redis-based rate limit storage for production use.

Uses Redis sorted sets with sliding window algorithm for accurate rate limiting across distributed systems.

Table of Contents

Interfaces

IRateLimitStorage
Interface for rate limit storage implementations.

Properties

$_config  : array<string|int, mixed>
$_prefix  : string
$_redis  : Redis|null

Methods

__construct()  : mixed
__destruct()  : mixed
Close Redis connection.
allow()  : bool
Check if a request is allowed under the rate limit.
clear()  : void
Clear all rate limit data (useful for testing).
getRemainingAttempts()  : int
Get the number of remaining attempts for a key.
getResetTime()  : int
Get the timestamp when the rate limit window resets.
reset()  : void
Reset the rate limit counter for a specific key.
getRedis()  : Redis
Get Redis connection.

Properties

Methods

__construct()

public __construct([array<string|int, mixed> $config = [] ]) : mixed
Parameters
$config : array<string|int, mixed> = []

Redis configuration

allow()

Check if a request is allowed under the rate limit.

public allow(string $key, int $limit, int $window) : bool
Parameters
$key : string

The unique identifier for the rate limit (e.g., IP address, user ID)

$limit : int

Maximum number of requests allowed in the window

$window : int

Time window in seconds

Tags
inheritDoc
Return values
bool

True if request is allowed, false if rate limit exceeded

clear()

Clear all rate limit data (useful for testing).

public clear() : void
Tags
inheritDoc

getRemainingAttempts()

Get the number of remaining attempts for a key.

public getRemainingAttempts(string $key, int $limit, int $window) : int
Parameters
$key : string

The unique identifier for the rate limit

$limit : int

Maximum number of requests allowed

$window : int

Time window in seconds

Tags
inheritDoc
Return values
int

Number of remaining attempts

getResetTime()

Get the timestamp when the rate limit window resets.

public getResetTime(string $key, int $window) : int
Parameters
$key : string

The unique identifier for the rate limit

$window : int

Time window in seconds

Tags
inheritDoc
Return values
int

Unix timestamp of reset time

reset()

Reset the rate limit counter for a specific key.

public reset(string $key) : void
Parameters
$key : string

The unique identifier to reset

Tags
inheritDoc

getRedis()

Get Redis connection.

private getRedis() : Redis
Tags
throws
RedisException
Return values
Redis

        
On this page

Search results