Skip to content

squaredbingo/redis-rate-limitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis Rate Limiter

A small, Redis-backed rate limiting utility for protecting endpoints and services. Provides atomic counters and configurable limits using Redis to store state.

Features

  • Simple Redis-backed limits (per-key)
  • Configurable limit and window
  • Atomic operations (Lua script or Redis INCR/EXPIRE pattern)
  • Minimal dependency surface — easy to integrate into any stack

Requirements

  • Redis (recommended 5.0+)
  • Your application runtime (Node)

Quickstart

  1. Clone the repo: git clone /path/to/your/repo
  2. Install runtime dependencies for your project (see language-specific files).
  3. Configure Redis connection via environment variable:
    • REDIS_URL=redis://localhost:6379

Usage (conceptual)

Library-style pseudocode:

const limiter = new RateLimiter({ redisUrl: process.env.REDIS_URL, limit: 100, windowSeconds: 60 });
const result = await limiter.consume('user:123'); // { allowed: true, remaining: 42, reset: 1580000000 }
if (!result.allowed) {
  // reject request (HTTP 429)
}

HTTP middleware example (pseudo):

  • On each request, call limiter.consume(key)
  • If allowed: continue and include headers:
    • X-RateLimit-Limit:
    • X-RateLimit-Remaining:
    • X-RateLimit-Reset:
  • If not allowed: respond 429 Too Many Requests

Configuration

Typical options:

  • redisUrl (string) — Redis connection string
  • limit (int) — number of tokens allowed per window
  • windowSeconds (int) — window size in seconds
  • keyPrefix (string) — prefix for Redis keys

Testing

  • Provide integration tests that point to a test Redis instance (use docker-compose or a local Redis).
  • Run unit tests with your language test runner.

Contributing

  • Open issues for bugs or feature requests.
  • Follow repository coding/style guidelines.
  • Add tests for new behavior.

License

MIT licence.

About

A small, Redis-backed rate limiting utility for protecting endpoints and services. Provides atomic counters and configurable limits using Redis to store state.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors