alisaifee / limits

Rate limiting using various strategies and storage backends such as redis & memcached
https://limits.readthedocs.org
MIT License
423 stars 59 forks source link

Support subsecond intervals and fraction rates #199

Closed petroslamb closed 8 months ago

petroslamb commented 9 months ago

First, great job in what I wish to become the needed defacto in python rate limiting.

My feature request is for sub second intervals, for example 1 request per 500 milliseconds and/or fractions of rates as well, like 0.5 requests per second. Possibly by lowering the base time unit to 1 millisecond from 1 second that appears to be now.

Do you think this is possible?

P.S. I am using the redis backend and i suspect when i try to mock Redis out with FakeRedis the custom running Lua scripts will raise an error. A helpful redis mock storage, based on the memory storage, could make it night and day for ones unittests 😸

alisaifee commented 8 months ago

First, great job in what I wish to become the needed defacto in python rate limiting.

Thank you, I'm glad it's been useful!

The subsecond interval feature is very interesting to me - however the main blocker towards implementing this is that redis (and the toy in memory storage) is (afaik) the only storage that will support it which makes it difficult to generalize.

alisaifee commented 8 months ago

A helpful redis mock storage, based on the memory storage, could make it night and day for ones unittests 😸

Is the built in MemoryStorage not usable for this purpose?