# token_bucket

> limit the number of request

Latest version **0.0.1** (published 2016-11-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install token_bucket
pnpm add token_bucket
yarn add token_bucket
bun add token_bucket
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2016-11-24 |
| First published | 2016-11-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | vinxent |

## Links

- npm: https://www.npmjs.com/package/token_bucket
- Repository: https://github.com/vincentgor/token_bucket
- Homepage: https://github.com/vincentgor/token_bucket#readme
- Issues: https://github.com/vincentgor/token_bucket/issues
- npm.io page: https://npm.io/package/token_bucket

## Recent versions

- 0.0.1 (latest) — 2016-11-24

## README

# token_bucket
具体用法详见example.js

这是一个用nodejs实现的简陋版令牌桶算法。支持redis和ioredis


```
'use strict';

const redis = require('ioredis');
const db = redis.createClient();

const Limit = require('./');

const interfaceIdArray= ['_300', '_550'];
const id = '23333';

const limiter_300 = new Limit({
    id: id,
    db: db,
    interfaceId: interfaceIdArray[0]
});
const limiter_550 = new Limit({
    id: id,
    db: db,
    interfaceId: interfaceIdArray[1]
});

// 模拟请求（300毫秒一次）
setInterval(() => {
    limiter_300.check((err, data) => {
        if (err) {
            console.log('err', err);
        } else {
            console.log('data', data);
        }
    });
}, 300);

// 模拟请求（550毫秒一次）
setInterval(() => {
    limiter_550.check((err, data) => {
        if (err) {
            console.log('err', err);
        } else {
            console.log('data', data);
        }
    });
}, 550);
```

---
_Source: https://npm.io/package/token_bucket · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
