Socket
Socket
Sign inDemoInstall

rate-limiter-flexible

Package Overview
Dependencies
Maintainers
1
Versions
163
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rate-limiter-flexible - npm Package Compare versions

Comparing version 2.3.12 to 2.4.0

33

lib/RateLimiterRedis.js

@@ -22,2 +22,3 @@ const RateLimiterStoreAbstract = require('./RateLimiterStoreAbstract');

* redis: RedisClient
* rejectIfRedisNotReady: boolean = false - reject / invoke insuranceLimiter immediately when redis connection is not "ready"
* }

@@ -33,2 +34,4 @@ */

this._rejectIfRedisNotReady = !!opts.rejectIfRedisNotReady;
if (typeof this.client.defineCommand === 'function') {

@@ -42,2 +45,24 @@ this.client.defineCommand("rlflxIncr", {

/**
* Prevent actual redis call if redis connection is not ready
* Because of different connection state checks for ioredis and node-redis, only this clients would be actually checked.
* For any other clients all the requests would be passed directly to redis client
* @return {boolean}
* @private
*/
_isRedisReady() {
if (!this._rejectIfRedisNotReady) {
return true;
}
// ioredis client
if (this.client.status && this.client.status !== 'ready') {
return false;
}
// node-redis client
if (typeof this.client.isReady === 'function' && !this.client.isReady()) {
return false;
}
return true;
}
_getRateLimiterRes(rlKey, changedPoints, result) {

@@ -62,2 +87,6 @@ let [consumed, resTtlMs] = result;

return new Promise((resolve, reject) => {
if (!this._isRedisReady()) {
return reject(new Error('Redis connection is not ready'));
}
const secDuration = Math.floor(msDuration / 1000);

@@ -112,2 +141,6 @@ const multi = this.client.multi();

return new Promise((resolve, reject) => {
if (!this._isRedisReady()) {
return reject(new Error('Redis connection is not ready'));
}
this.client

@@ -114,0 +147,0 @@ .multi()

2

package.json
{
"name": "rate-limiter-flexible",
"version": "2.3.12",
"version": "2.4.0",
"description": "Node.js rate limiter by key and protection from DDoS and Brute-Force attacks in process Memory, Redis, MongoDb, Memcached, MySQL, PostgreSQL, Cluster or PM",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -183,2 +183,3 @@ [![Coverage Status](https://coveralls.io/repos/animir/node-rate-limiter-flexible/badge.svg?branch=master)](https://coveralls.io/r/animir/node-rate-limiter-flexible?branch=master)

* [timeoutMs](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#timeoutms) For Cluster.
* [rejectIfRedisNotReady](https://github.com/animir/node-rate-limiter-flexible/wiki/Options#rejectifredisnotready)

@@ -185,0 +186,0 @@ ## API

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