animir / node-rate-limiter-flexible

Atomic counters and rate limiting tools. Limit resource access at any scale.
ISC License
3.06k stars 159 forks source link

RateLimiterRes: Expose duration variable when using fixed window #199

Closed oskar-rosen-ui closed 1 year ago

oskar-rosen-ui commented 1 year ago

I use RateLimiterUnion with two instances of RateLimiterRedis and I'm using different fixed windows.

When the limit is reached for one of the rate limiters in this union, it would be great it could include the duration variable (if it was provided) in the RateLimiterRes object.

animir commented 1 year ago

@oskar-rosen-ui RateLimiterUnion returns object with keyPrefix limiter option as object key, e.g. { limit1: RateLimiterRes { ... }, limit2: RateLimiterRes {.... } }. You can get any option like duration from your configured limiter by that prefix.

See full example with limiter keyPrefix here

oskar-rosen-ui commented 1 year ago

@animir thank you for your quick response. That's how I've already implemented it, so I will continue doing so.

animir commented 1 year ago

@oskar-rosen-ui I think this is the best to keep standard response format for all types of limiters from this package. I am closing this issue. Feel free to reopen if something pops up.