Closed Eligioo closed 2 years ago
Hi 👋
May I ask why would you need something like that, is there any particular scenario you are facing? I don't think something like that is possible, since Rate->interval
is always a time interval in seconds, there's no way to specify exact minutes.
I think the only way to achieve what you want is to change the way key is generated as in case of Redis backend for example: https://github.com/nikolaposa/rate-limit/blob/master/src/RedisRateLimiter.php#L42.
Thank you for your answer. The scenario I'm facing is that the external system I'm trying to rate limit against is working with real minutes hence I try to simulate that. But the system doesn't provide the information on how much calls I have left per clock minute.
Can you be more explicit what you meant with the way the key is generated?
Ok I figured out what you meant with the generated Redis key! Now I also understand why it resets every second. It's because the interval is suffixed to the Redis key. I'll look into it! Thanks for giving me a direction.
UPDATE:
Removing the :$interval
in private function key
already does the trick but I'll come up with something better.
Exactly, so what I meant is basically some custom strategy for generating keys such as: $key:$minute
or something like that. Not sure, but I think that even custom Rate
implementation is needed.
Yes that's what I exactly did, create a new RedisRateLimiter with a modified key
method. It's working as expected now.
Hi @nikolaposa
With the
Rate::custom
I'm trying to simulate real minutes (12:00, 12:01, 12:02, etc.) rather than 1 minute based on the first call (12:00:30 --> 12:01:30). I tried it with the following setup:The
$status->getResetAt()
gets calculated correctly but the problem I'm facing is that the$status->getRemainingAttempts()
resets every second. This is probably due to the$now->diffInSeconds($nextMinute)
used for the custom rate changes every second. Any suggestion on how to make this work?