-
Notifications
You must be signed in to change notification settings - Fork 450
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
Fix redis TTL to match limit reset time #351
Comments
UPDATE: I've created a PR for this fix (#490) This is actually still kind of buggy. You fix the TTL in Redis, but the retry-after headers will still be wrong. This is the basic change that allows this to be fixed: First, adjust the LUA Script so that it returns the current TTL as well as counter.
Then, adjust IncrementAsync as follows:
This makes it so since we don't have an actual 'first call'-time, we can just take the current time minus the interval plus the TTL, which gives us a first cache time which is within a second of the actual time, which should suffice for the accuracy of the rate limiting. The timeout variable for the LUA Script is only used when no entry exists, so we can just always set that to interval.TotalSeconds. Hope that helps. |
Currently redis ttl is set to max value even if request is made at the end of interval. This can be confusing to API users and is misleading.
I suggest a small change to the Increment async method to calculate how much time there is left to next interval.
The text was updated successfully, but these errors were encountered: