Bump! :)
RateLimiter::attempts using Redis
Hello everyone,
I'm working on a personal project using Laravel 9.
Some of my routes are throttled by the throttle middleware, configured to work with Redis on the $routeMiddleware from the Kernel.
While working with the "normal" ThrottleRequests::class, my code is working as expected.
But as soon as I'm switching for ThrottleRequestsWithRedis::class, the RateLimiter::attempts($key) doesn't seem to retrieve the values from Redis and return 0 instead of the actual count.
Did someone already find a way to correctly match the key and/or fetch it from Redis? After 2 hours of reading the middleware classes, I couldn't figure out :(
To give you some context, below, are the configurations while running with Redis:
// Kernel.php
// ...
protected $routeMiddleware = [
// ...
// 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequestsWithRedis::class,
// ...
];
// RouteServiceProvider.php
protected function configureRateLimiting()
{
// ...
RateLimiter::for('auth_registration', function (Request $request) {
return Limit::perMinute(10)->by($request->ip());
});
}
// somewhere on my project
// ...
$key = md5('auth_registration'.$request->ip());
RateLimiter::attempts($key); // always return 0 with Redis
// ...
RateLimiter::clear($key);
Thank you for your help!
Please or to participate in this conversation.