Closed Gnoll94 closed 10 months ago
Hey, the expiry on the key is actually not used to do ratelimiting in this case. We could do it like that but right now it's not instead we're creating a new key per window and just adding expiry to eventually clean up everything.
you can very easily calculate the end of the window from the key itself:
const windowDuration = 10000 // milliseconds
const bucket = Math.floor(Date.now() / windowDuration);
const reset = (bucket + 1) * windowDuration;
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity.
I got sidetracked from this for a while, but I'm not sure this addresses the issue I was having. I essentially just need to do
const result = await ratelimit.limit(identifier);
If the identifier is already rateLimited, I'd like to get the TTL of it (How much longer is left on the rate limit?) Based off the data being returned from this. Is that a possible value to figure out?
I'm trying to get an accurate TTL for a rate limit I have set up using Upstash
My rate limit is set up like
I then have the following headers being set
When I make the request & get back the
result.reset
it doesn't seem to match what I'd expect. Am I looking at the wrong field to get the key TTL?In this case, I have my Data Browser fully cleared beforehand & cache flushed. When I make the request and go into the Upstash viewer, I can find the key & the expiration it has is correct (A single request, 4 hour limit, 14400s)
However, the
result.reset
value I'm getting back from this same callawait ratelimit.limit(identifier);
doesn't match up to the Upstash TTLIt never seems to give me back anything that's useable to identify when the limit expires, sometimes seemingly giving me the same UNIX timestamp even after clearing the DB. Not sure if there's something I'm missing about my implementation?