losant / redis-gcra Goto Github PK
View Code? Open in Web Editor NEWRate limiting based on Generic Cell Rate Algorithm
License: MIT License
Rate limiting based on Generic Cell Rate Algorithm
License: MIT License
I had check the lua script and found some part unexpected:
// https://github.com/Losant/redis-gcra/blob/master/lib/gcra.lua#L51
redis.call("SET", rate_limit_key, new_tat, "EX", reset_in)
The expire time of the key will be set to reset_in in seconds(EX), but in the reset_in value is in milliseconds.
That means that in most cases, the key will not expire at all(because it requires so much time to expire and will be reset in a short time).
Although this does not influence the whole functionality of the gcra algorithm because it will take the bigger one between now and the value of the key:
// https://github.com/Losant/redis-gcra/blob/master/lib/gcra.lua#L19
tat = math.max(tat, now)
But I think it should be corrected in case of making confusion.
I'm trying to set up a simple password rate limiter, and I want to allow 6 attempts per minute.
I set it up like this:
const {limited, retryIn} = await limiter.limit({
key: `signin/email/${email.trim().toLowerCase()}`,
burst: 6,
rate: 6,
period: 60000,
cost: 1
});
When I do too many sign ins I eventually get a retryIn of 10, but then it gets down to below 5 and then the next request is allowed!
Is this an issue with the rate limiter allowing too many requests through, or an issue with the retryIn?
Or is it an issue in how I'm configuring this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.