lua script v1
This commit is contained in:
parent
15bf74f770
commit
86d4f8e219
@ -50,7 +50,7 @@ module.exports = function rateLimitMiddleware (metadataBackend) {
|
||||
getStoreKey(user, endpointGroup), // KEY[1]
|
||||
getStatusKey(user, endpointGroup) // KEY[2]
|
||||
];
|
||||
|
||||
|
||||
metadataBackend.redisCmd(REDIS_DB, 'EVAL', redisParams, function(err, {isBloqued, limit, remaining, retry, reset}) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@ -108,9 +108,9 @@ function getStatusKey(user, endpointGroup) {
|
||||
return USER_KEY_REDIS + user + ':' + endpointGroup;
|
||||
}
|
||||
|
||||
function getLuaScript(maxBurst, period) {
|
||||
function getLuaScript() {
|
||||
return `
|
||||
local max = redis.call("HGETALL", KEYS[1])
|
||||
return redis.call("CL.THROTTLE", KEYS[2], ${maxBurst}, max, ${period})
|
||||
local userValues = redis.call("HGETALL", KEYS[1])
|
||||
return redis.call("CL.THROTTLE", KEYS[2], userValues[b], userValues[c], userValues[p])
|
||||
`;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user