rate-limiter-flexible
Advanced tools
Comparing version 0.4.0 to 0.4.1
module.exports = class BlockedKeys { | ||
constructor() { | ||
this._keys = {}; // {'key': 1526279430331} | ||
this._length = 0; | ||
this._addedKeysAmount = 0; | ||
} | ||
@@ -16,3 +16,3 @@ | ||
this._length = Object.keys(this._keys).length; | ||
this._addedKeysAmount = Object.keys(this._keys).length; | ||
} | ||
@@ -28,4 +28,4 @@ | ||
this._keys[key] = Date.now() + sec * 1000; | ||
this._length++; | ||
if (this._length > 999) { | ||
this._addedKeysAmount++; | ||
if (this._addedKeysAmount > 999) { | ||
this.collectExpired(); | ||
@@ -32,0 +32,0 @@ } |
@@ -46,3 +46,3 @@ const expect = require('chai').expect; | ||
blockedKeys.add('key1', 1); | ||
expect(Object.keys(blockedKeys._keys).length === 1 && blockedKeys._length === 1).to.equal(true); | ||
expect(Object.keys(blockedKeys._keys).length === 1 && blockedKeys._addedKeysAmount === 1).to.equal(true); | ||
done(); | ||
@@ -56,3 +56,3 @@ }, 1001); | ||
blockedKeys.msBeforeExpire('key'); | ||
expect(Object.keys(blockedKeys._keys).length === 1 && blockedKeys._length === 1).to.equal(true); | ||
expect(Object.keys(blockedKeys._keys).length === 1 && blockedKeys._addedKeysAmount === 1).to.equal(true); | ||
done(); | ||
@@ -59,0 +59,0 @@ }, 1001); |
{ | ||
"name": "rate-limiter-flexible", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Flexible API rate limiter backed by Redis for distributed node.js applications", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
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
80822