0.0.4 • Published 11 months ago

@tehdev/rate-limiter-redis v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Distributed redis rate limiter

This package is implementaion of an abstract rate limiter

How use

  1. Install package npm i @tehdev/rate-limiter-redis
  2. Install redis package npm i ioredis
  3. Initialize rate limiter
import { RateLimiterRedis, RateConfig } from "@tehdev/rate-limiter-redis";
import Redis from "ioredis";

const clients = {
  client_1: new RateConfig(10, 1000), // 10 rps for client_1
};

const redis = new Redis(redisOptions);

const rateLimiter = new RateLimiterRedis(clients, redis);
  1. Start rate limiter server (create quota). When you run server on many instances from all instances rateLimiter will choose master node. Only this node will isue a quota to the all nodes.
rateLimiter.run();
  1. Use quota
await rateLimiter.wait("client_1"); // return True when quota exists
0.0.3

11 months ago

0.0.2

11 months ago

0.0.4

11 months ago

0.0.1

1 year ago