The problem with the current approach is that by calling PEXPIRE with the refill interval, the refill rate will be ignore and always replaced with the maximum number of tokens - the current request.
Instead of that, I suggest that we allow the remaining requests to go below 0 (to be able to check if the request should pass or not). Then, if an interval has passed, we check the number of remaining tokens. If it its negative, we simply replace it with the refill rate, which is otherwise added to the remaining tokens.
The problem with the current approach is that by calling
PEXPIRE
with the refill interval, the refill rate will be ignore and always replaced with the maximum number of tokens - the current request.Instead of that, I suggest that we allow the remaining requests to go below 0 (to be able to check if the request should pass or not). Then, if an interval has passed, we check the number of remaining tokens. If it its negative, we simply replace it with the refill rate, which is otherwise added to the remaining tokens.