Have ideas to improve npm?Join in the discussion! »

    rate-limit-redis
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/rate-limit-redis package

    2.1.0 • Public • Published

    Rate Limit Redis

    Build Status NPM version Dependency Status Development Dependency Status

    Redis client for the express-rate-limit middleware.

    Install

    $ npm install --save rate-limit-redis

    Usage

    const RateLimit = require("express-rate-limit");
    const RedisStore = require("rate-limit-redis");
    
    const limiter = new RateLimit({
      store: new RedisStore({
        // see Configuration
      }),
      max: 100, // limit each IP to 100 requests per windowMs
      delayMs: 0, // disable delaying - full speed until the max limit is reached
    });
    
    //  apply to all requests
    app.use(limiter);

    Connect to UDP Socket

    const RateLimit = require("express-rate-limit");
    const RedisStore = require("rate-limit-redis");
    const Redis = require("ioredis");
    const client = new Redis("/tmp/redis.sock");
    
    const limiter = new RateLimit({
      store: new RedisStore({
        client: client,
      }),
      max: 100, // limit each IP to 100 requests per windowMs
      delayMs: 0, // disable delaying - full speed until the max limit is reached
    });

    Configuration

    • expiry: seconds - how long each rate limiting window exists for. Defaults to 60.
    • resetExpiryOnChange: boolean - if the expiry time should be reset every time a key is incremented/decremented. This means that when the limit is reached and the user is given a 429 response, the rate limit window is extended. Defaults to false.
    • prefix: string - prefix to add to entries in Redis. Defaults to rl:.
    • client: Redis Client or ioredis Client- A Redis Client to use. Defaults to require('redis').createClient();.
    • redisURL: string - a Redis connection string to be used for the default client connection. Ignored when the client option is provided. Redis Client connection string format and options.
    • passIfNotConnected: boolean - If Redis is not connected, let the request succeed as failover. Defaults to false.

    License

    MIT © Wyatt Johnson, Nathan Friedly

    Keywords

    none

    Install

    npm i rate-limit-redis

    DownloadsWeekly Downloads

    70,350

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    13.2 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar