andrewdyer/predis-request-limiter

Request rate limiting using Predis.

2.0.0 2023-01-26 22:09 UTC

This package is auto-updated.

Last update: 2024-04-27 01:18:33 UTC


README

Request rate limiting using Predis.

Total Downloads Latest Stable Version License

License

Licensed under MIT. Totally free for private or commercial projects.

Installation

composer require andrewdyer/predis-request-limiter

Usage

// Create new predis client instance
$predis = new Predis\Client();

// Create new limiter instance
$limiter = new Anddye\PredisRequestLimiter\Limiter($predis, 100);
$limiter->setRateLimit(10, 30)
    ->setStorageKey('api:limit:%s');

if ($limiter->hasExceededRateLimit()) {
    // Too many requests has been made, display error message
} else {
    $limiter->incrementRequestCount();
}

Support

If you are having any issues with this library, then please feel free to contact me on Twitter.

If you think you've found an bug, please report it using the issue tracker, or better yet, fork the repository and submit a pull request.

If you're using this package, I'd love to hear your thoughts!

Useful Links