# request-limit

> 通过redis缓存实现token对url的访问频率控制

Latest version **1.0.12** (published 2018-01-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install request-limit
pnpm add request-limit
yarn add request-limit
bun add request-limit
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2018-01-22 |
| First published | 2017-09-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | chheng |
| Maintainers | chheng |
| Keywords | request-limit, request, limit, rate |

## Links

- npm: https://www.npmjs.com/package/request-limit
- Repository: https://github.com/chhenghua/request-limit
- Homepage: https://github.com/chhenghua/request-limit#readme
- Issues: https://github.com/chhenghua/request-limit/issues
- npm.io page: https://npm.io/package/request-limit

## Dependencies (1)

- [redis](https://npm.io/package/redis.md) ^2.8.0

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.0.12 (latest) — 2018-01-22
- 1.0.10 — 2018-01-22
- 1.0.9 — 2018-01-15
- 1.0.8 — 2017-10-10
- 1.0.7 — 2017-09-28
- 1.0.6 — 2017-09-26
- 1.0.5 — 2017-09-26
- 1.0.4 — 2017-09-26
- 1.0.3 — 2017-09-18
- 1.0.2 — 2017-09-18
- 1.0.1 — 2017-09-18
- 1.0.0 — 2017-09-14

## README

通过redis缓存实现token对url的访问频率控制

#### token可为登录用户的ticket

### 安装
```bash
$ npm install request-limit
```

### 初始化
```js
const limit = require('request-limit')
const urlMap = new Map()
urlMap.set('/api/user/getList.get', {limit: 2, interval: 20})
urlMap.set('/api/user/add.post', {limit: 2, interval: 2})
urlMap.set('/api/user/getOne.get', {limit: 2, interval: 2})

// 白名单
const whiteList = []
whiteList.push('/api/login.post')

limit.init(urlMap, {
    store: {
        host: '127.0.0.1',
        port: 6379
    },
    whiteList
})
```
#### 其中，后面的参数为多少秒内访问多少次
#### 如果不在urlMap里面设置，则使用默认配置24小时内访问1000次
#### 在白名单中的url不受限制

### 使用
```js
const limitRlt = await limit.checkLimit('token', 'url.post')
await limit.record('token', 'url.post')

```

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