Closed ttamg closed 9 months ago
At the moment using the test
method would be the way to go - this is used in the Flask-Limiter library to do conditional rate limiting (pretty much what it looks like you're trying to do). The extra hit to the backend is indeed unfortunate but the implementation of the moving window strategy is not so simple in terms of implementing a deduction.
Closing due to inactivity
Great package and very useful thanks.
My use case is where I use the rate limiter at the start of a long-running request, but want to only count the 'hit' if the response does not fail and return an exception. If a client hits the API and gets and error response then they should not have to 'pay for it' that time.
I see a workaround for this is to use the
.test()
on the way in and at the end of my call use the full.hit()
to increment the rate limiter. This feels a bit clunky and hits Redis twice.Instead is there a way to do this by applying the
.hit()
at the start of the request and then if an exception is raised, catch that and call another.hit()
with a cost of -1 or similar? I can and will test it but thought I would raise as a feature query / request.Thanks. Matt