-
Notifications
You must be signed in to change notification settings - Fork 982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throttle only supports synchronous datastores #381
Comments
Hi, No, it probably needs to be refactored to work with redis or something. And yes, I would happily offload this; I'd probably leave what's there in, and just point people at the external one. |
@brycebaril did you manage to pull this off? |
@gergelyke Yes, to an extent -- I made https://npmjs.org/package/tokenthrottle-redis which you should be able to plug in similarly to restify. It is heavily based on @mcavage 's implementation. I haven't gone through the effort of writing up how to plug it into restify, however. |
Could you do that please? |
Having looked briefly at On Fri, Feb 7, 2014 at 8:19 AM, Bryce Baril notifications@github.comwrote:
|
Just finished up a project where we needed a redis backed store for our throttling. Utilized https://npmjs.org/package/tokenthrottle-redis by @brycebaril Here's a quick snippet of the pattern I used:
If you need something more configurable, you could turn this into a configurable middleware, similar to the throttle plugin that ships with restify. But for my purposes, only needed username throttling and no overrides for example. |
Closes: #289 #381 #474 #575 #790 #633 #717 #576 #576 #909 #875 #860 #853 #850 #829 #813 #801 #921 #1101 #1019 #989 #632 #708 #737 #859 #1326 #1327 #927 #1099 #1068 #1040 #1035 #957 #948 #1134 #1136 #1183 #1206 #1286 #1323 > Note: this issue closes _but does not resolve_ the issues listed, we are just tracking them in another medium
I was looking for a more configurable rate limit module this nest plugin does axactly what we want |
From the API Guide:
I went to create a Redis tokensTable and quickly noticed that it won't actually work because for Redis the
tokensTable.get
needs to be asynchronous. The way thatTokenBucket
works also expects the same bucket instance to be used.So I went and made backwards-compatible modifications to tokens.js that allow you to use either synchronous or asynchronus TokensTable implementations, which only changes the api for async ones such that it doesn't break any existing versions.
I've got it nearly there, but the more I work on it the more I think a larger-order refactor of the throttle.js would make things a lot easier (or at least cleaner). I don't mind doing this, but I'm thinking if I did, it may be a reasonable time to extract it from restify into its own module.
So my questions are:
First: Am I missing something here that would make it feasible to use an async TokensTable with the current implementation and wasting my time?
Second: If I make a new external throttle module that supports both the backwards-compatible synchronous TokensTable and asynchronous versions, would you accept a pull request that removes the existing implementation for a dependency on the new one?
The text was updated successfully, but these errors were encountered: