A small, Redis-backed rate limiting utility for protecting endpoints and services. Provides atomic counters and configurable limits using Redis to store state.
- 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
- Redis (recommended 5.0+)
- Your application runtime (Node)
- Clone the repo: git clone /path/to/your/repo
- Install runtime dependencies for your project (see language-specific files).
- Configure Redis connection via environment variable:
- REDIS_URL=redis://localhost:6379
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
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
- 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.
- Open issues for bugs or feature requests.
- Follow repository coding/style guidelines.
- Add tests for new behavior.
MIT licence.