Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cartodb-redis

Package Overview
Dependencies
Maintainers
17
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cartodb-redis - npm Package Compare versions

Comparing version 0.16.0 to 1.0.0

package-lock.json

113

lib/carto_metadata.js

@@ -47,2 +47,3 @@ /**

oauth_metadata_db: 3,
rate_limits_db: 8,
user_key: dot.template("rails:users:{{=it.username}}"),

@@ -58,3 +59,6 @@ oauth_user_key: dot.template("rails:oauth_access_tokens:{{=it.oauth_access_key}}"),

user_tiler_limits: dot.template("limits:tiler:{{=it.username}}"),
user_timeout_limits: dot.template("limits:timeout:{{=it.username}}") // db & render timeouts
user_timeout_limits: dot.template("limits:timeout:{{=it.username}}"), // db & render timeouts
rate_limits_sha_script: null,
rate_limits_store_key: dot.template("limits:rate:store:{{=it.username}}:{{=it.app}}:{{=it.endpointGroup}}"),
rate_limits_status_key: dot.template("limits:rate:status:{{=it.username}}:{{=it.app}}:{{=it.endpointGroup}}")
};

@@ -525,2 +529,109 @@

me.rateLimitLuaScript =
'local results = {} ' +
'local resultsCounter = 0 ' +
'local limits = {} ' +
'local limitsArray = redis.call("LRANGE", KEYS[1], 0, -1) ' +
'for i, v in ipairs(limitsArray) do ' +
' local rest = i % 3 ' +
' if rest ~= 0 then ' +
' limits[rest] = v ' +
' else ' +
' resultsCounter = resultsCounter + 1 ' +
' results[resultsCounter] = redis.call("CL.THROTTLE", KEYS[2], limits[1], limits[2], v) ' +
' end ' +
'end ' +
'return results'
;
me.loadRateLimitsScript = function(callback) {
this.redisCmd(me.rate_limits_db, 'SCRIPT', ['LOAD', me.rateLimitLuaScript], function (err, sha) {
if (!err && sha) {
me.rate_limits_sha_script = sha;
}
if(callback) {
callback(err, sha)
}
});
};
me.getRateLimit = function(username, app, endpointGroup, callback) {
var params = [
this.rate_limits_sha_script ? this.rate_limits_sha_script : this.rateLimitLuaScript,
2,
this.rate_limits_store_key({
username: username,
app: app,
endpointGroup: endpointGroup
}), // KEY[1]
this.rate_limits_status_key({
username: username,
app: app,
endpointGroup: endpointGroup
}) // KEY[2]
];
this.redisCmd(
me.rate_limits_db,
me.rate_limits_sha_script ? 'EVALSHA' : 'EVAL',
params,
function (err, rateLimits) {
if (err) {
if (err.name === 'ReplyError' && err.message === 'NOSCRIPT No matching script. Please use EVAL.') {
me.rate_limits_sha_script = null;
me.getRateLimit(username, app, endpointGroup, callback);
} else {
callback(err);
}
} else {
callback(null, me.getLowerRateLimit(rateLimits));
}
}
);
};
/**
* Returns the inner rateLimit what is the strictest one or undefined
* @param {Array} rateLimits Each inner array has 5 integers indicating:
* isBloqued, limit, remaining, retry, reset
*/
me.getLowerRateLimit = function(rateLimits) {
if (!Array.isArray(rateLimits) || !rateLimits.length) {
return;
}
var minIndex;
var minRemainingValue;
for (var currentIndex = 0; currentIndex < rateLimits.length; currentIndex++) {
var rateLimit = rateLimits[currentIndex];
if (!me.validateRatelimit(rateLimit)) {
continue;
}
var isBlocked = rateLimit[0]
var remaining = rateLimit[2];
if (isBlocked === 1) {
minIndex = currentIndex;
break;
}
if (minRemainingValue === undefined || remaining < minRemainingValue) {
minIndex = currentIndex;
minRemainingValue = remaining;
}
}
return rateLimits[minIndex];
};
me.validateRatelimit = function(rateLimit) {
return rateLimit.length === 5;
};
/*******************************************************************************************************************

@@ -527,0 +638,0 @@ * END LIMITS

4

package.json
{
"name": "cartodb-redis",
"version": "0.16.0",
"version": "1.0.0",
"main": "./lib/carto_metadata.js",

@@ -31,4 +31,4 @@ "description": "A Node.js based lib to interact with cartodb redis databases",

"engine": {
"node": ">= 0.6"
"node": ">= 6.9.0"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc