# @kuroismith/ratelimiter

> A rate limiter based on token bucket algorithm using redis

Latest version **0.0.1** (published 2018-09-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kuroismith/ratelimiter
pnpm add @kuroismith/ratelimiter
yarn add @kuroismith/ratelimiter
bun add @kuroismith/ratelimiter
```

## 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 | 2018-09-27 |
| First published | 2018-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 53.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kuroismith |
| Maintainers | kuroismith |

## Links

- npm: https://www.npmjs.com/package/@kuroismith/ratelimiter
- Repository: https://github.com/kuroismith/raterlimiter
- Homepage: https://github.com/kuroismith/raterlimiter#readme
- Issues: https://github.com/kuroismith/raterlimiter/issues
- npm.io page: https://npm.io/package/@kuroismith/ratelimiter

## Dependencies (3)

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

## Recent versions

- 0.0.1 (latest) — 2018-09-27

## README

# RateLimiter

A rate limiter based on token bucket algorithm using redis

# Usage

```typescript
  // redis client
  let client: RedisClient = redis.createClient({host: "127.0.0.1"});

  // In every 20000 milliseconds, the resource can be access 100 times
  const policy: RateLimiterPolicy = new SimpleRateLimiterPolicy({
    interval: 20000,
    capacity: 100,
    maxBurstTime: 1000
  });

  const limiter: RateLimiter = new RedisRateLimiter(policy, client);

  async action(userId) {
    try {
        const accessible = await limiter.access(userId);
        if (accessible) {
          // allowed
        } else {
          // limit is exceeded, action is not allowed
        }
    } catch (e) {
        // redis failed or similar
    }
  }
```

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