rate-limiter-flexible
Advanced tools
Comparing version 2.3.12 to 2.4.0
@@ -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() |
{ | ||
"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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123485
3363
240