IRateLimitStorage
in
Interface for rate limit storage implementations.
Provides a consistent API for tracking and enforcing rate limits across different storage backends (Redis, File, Memory, etc).
Table of Contents
Methods
- 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.
Methods
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
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
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
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
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