nikolaposa / rate-limit

🚔 General purpose rate limiter implementation.
MIT License
271 stars 47 forks source link

Add array support #22

Closed cmizzi closed 4 years ago

cmizzi commented 4 years ago

This simple addition makes it possible to support an array in order to use the rate limit (no need for Redis). Of course, it removes the cluster side but there are cases where it is interesting not to use Redis but a simple array to use the rate limit as an example simple scripts with a token that is not present in the database but hardcoded.

It might also be interesting to create an abstract class in order to make all the different possible supports.

nikolaposa commented 4 years ago

Could you provide more examples where this in-memory rate limiter implementation makes sense? I'm not convinced that it could be useful anywhere else but in unit tests for example.

cmizzi commented 4 years ago

Could you provide more examples where this in-memory rate limiter implementation makes sense? I'm not convinced that it could be useful anywhere else but in unit tests for example.

nikolaposa commented 4 years ago

I developed the support this way to best match the implemented version of Redis.

I think that's not a valid reason, why does it need to have same internals as the one using Redis as a backend? In-memory rate limiter is supposed to be lightweight, optimized for performance, and I feel like modeling it after Redis, Memcached or any other implementation is not necessary and can be counter-productive.

cmizzi commented 4 years ago

The implementation is light, it only calls for a few methods that make it easier to understand what's going on, the reading is fluid in my opinion. It's very easily readable and understandable. But if it bothers you, I can implement a "lighter" version.

nikolaposa commented 4 years ago

@cmizzi Any updates on the alternative version?

cmizzi commented 4 years ago

@nikolaposa Sorry, I haven't had time to look yet. I'm watching this ASAP.

nikolaposa commented 4 years ago

Closing in favor of: https://github.com/nikolaposa/rate-limit/pull/32