- Home
- Skills
- APIs & Backend
- API Rate Limiting Redis Strategist
Works with the AI Agents you already use
API Rate Limiting Redis Strategist
Implement distributed API rate limiting using atomic Redis Lua scripts and standard IETF headers.
$15
API Rate Limiting Redis Strategist
Example session with this skill installed
I need to implement a sliding window rate limiter in Redis for my Express.js API. Use Lua scripts for atomicity and include standard IETF headers.
- Read your context and instructions
- Compiled the api rate limiting
I have generated a high-performance Sliding Window Counter implementation using an atomic Redis Lua script and Express.js middleware.
Redis Sliding Window Implementation
// rateLimiter.js
const Redis = require('ioredis');
const redis = new Redis(process.env.REDIS_URL);
const SLIDING_WINDOW_LUA = `
local key = KEYS[1]
local now = tonumber(ARGV[1])
local window = tonumber(ARGV[2])
local limit = tonumber(ARGV[3])
redis.call('ZREMRANGEBYSCORE', key, 0, now - window)
local current_count = redis.call('ZCARD', key)
if current_count < limit then
redis.call('ZADD', key, now, now)
redis.call('EXPIRE', key, window / 1000)
return {limit, limit - current_count - 1, 0}
else
local oldest = redis.call('ZRANGE', key, 0, 0, 'WITHSCORES')
local retry_after = 0
if #oldest > 0 then
retry_after = math.max(0, math.ceil((tonumber(oldest[2]) + window - now) / 1000))
end
return {limit, 0, retry_after}
end
`;
async function rateLimit(req, res, next) {
const key = `rate_limit:${req.ip}`;
const now = Date.now();
const windowMs = 60000; // 1 minute
const limit = 100;
const [max, remaining, retryAfter] = await redis.eval(
SLIDING_WINDOW_LUA, 1, key, now, windowMs, limit
);
res.setHeader('RateLimit-Limit', max);
res.setHeader('RateLimit-Remaining', remaining);
res.setHeader('RateLimit-Reset', Math.ceil(windowMs / 1000));
if (remaining === 0 && retryAfter > 0) {
res.setHeader('Retry-After', retryAfter);
return res.status(429).json({ error: 'Too Many Requests' });
}
next();
}
module.exports = rateLimit;
Next steps
- Add
REDIS_URLto your.envfile. - Apply the
rateLimitmiddleware to your sensitive routes inapp.js. - Verify header presence using
curl -Ion your local endpoint.
Connects securely to your tools. The creator never sees your data.
About this skill
Managing API traffic spikes in a distributed environment often leads to race conditions and inaccurate limit tracking. This skill provides production-ready rate limiting logic using atomic Redis operations to ensure consistency across multiple service instances.
What it does
- Algorithm selection identifies whether Sliding Window Counter or Token Bucket best fits your specific traffic profile.
- Atomic Lua scripting bundles Redis commands into a single roundtrip to prevent race conditions without complex locking.
- IETF header injection implements standard
RateLimit-Limit,RateLimit-Remaining, andRateLimit-ResetHTTP headers. - Error handling generates compliant
429 Too Many Requestsresponses includingRetry-Afterlogic. - Middleware generation outputs integration code for Node.js or Python backend stacks.
How it works
- Analyze Requirements to determine if you need burst tolerance or strict accuracy.
- Generate Lua Scripts using commands like
ZREMRANGEBYSCOREandZCARDfor high-performance set management. - Configure Headers to match IETF standards for client-side rate limit awareness.
- Implement Middleware by wrapping your existing API routes with the generated Redis logic.
Frameworks & tools
This skill focuses on Redis for state management and Lua for atomicity. It provides integration code primarily for Node.js and Python backend environments.
Why this beats prompting it yourself
Generic prompts often produce non-atomic code that fails under high concurrency or produces inaccurate counts. This skill enforces atomic Redis operations and strictly follows IETF header standards to ensure your rate limiting is both reliable and developer-friendly.
Use cases
- Prevent API abuse by implementing per-user sliding window limits.
- Manage shared resource access across a distributed microservices cluster.
- Standardize rate limit headers for public-facing developer APIs.
- Handle sudden traffic bursts using a burst-tolerant Token Bucket implementation.
Known limitations
Restricted to Redis-backed implementations. Requires a Node.js or Python environment for the middleware wrappers.
Requires Redis. Limited to Node.js and Python middleware. Workspace restricted to active project directory.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 3 days ago
Requires
Permissions
Target Use Cases: - Implement sliding window rate limiting in Redis with Lua. - Configure API rate limiting with IETF RateLimit headers. - Build a distributed rate limiter for microservices in Node.js.