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

async-ratelimiter

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-ratelimiter - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change Log

<a name="1.1.4"></a>
## [1.1.4](https://github.com/microlinkhq/async-ratelimiter/compare/v1.1.3...v1.1.4) (2019-03-27)
<a name="1.1.3"></a>

@@ -7,0 +12,0 @@ ## 1.1.3 (2018-12-17)

3

package.json

@@ -5,3 +5,3 @@ {

"homepage": "https://documentup.com/microlinkhq/async-ratelimiter",
"version": "1.1.3",
"version": "1.1.4",
"main": "src/index.js",

@@ -17,2 +17,3 @@ "author": {

"Ayan Yenbekbay <ayan.yenb@gmail.com>",
"Nico Kaiser <nico@kaiser.me>",
"amanda <amandalucis@gmail.com>"

@@ -19,0 +20,0 @@ ],

@@ -122,3 +122,9 @@ # async-ratelimiter

##### decrease
Type: `boolean`
When set to `false`, the remaining number of calls is not decreased. This is useful for just reading the remaining calls without actually decreasing them.
## License

@@ -125,0 +131,0 @@

@@ -17,3 +17,8 @@ 'use strict'

async get ({ id = this.id, max = this.max, duration = this.duration } = {}) {
async get ({
id = this.id,
max = this.max,
duration = this.duration,
decrease = true
} = {}) {
assert(id, 'id required')

@@ -28,15 +33,14 @@ assert(max, 'max required')

const res = await db
.multi()
.zremrangebyscore([key, 0, start])
.zcard([key])
.zadd([key, now, now])
.zrange([key, 0, 0])
.zrange([key, -max, -max])
.pexpire([key, duration])
.exec()
const pipeline = db.multi()
pipeline.zremrangebyscore([key, 0, start])
pipeline.zcard([key])
if (decrease) pipeline.zadd([key, now, now])
pipeline.zrange([key, 0, 0])
pipeline.zrange([key, -max, -max])
pipeline.pexpire([key, duration])
const res = await pipeline.exec()
const count = parseInt(res[1][1])
const oldest = parseInt(res[3][1])
const oldestInRange = parseInt(res[4][1])
const oldest = parseInt(res[decrease ? 3 : 2][1])
const oldestInRange = parseInt(res[decrease ? 4 : 3][1])
const resetMicro =

@@ -43,0 +47,0 @@ (Number.isNaN(oldestInRange) ? oldest : oldestInRange) + duration * 1000

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