@aegiskit/store-upstash
v0.1.0
Published
Atomic, serverless-correct rate-limit store for Aegis, backed by Upstash Redis.
Maintainers
Readme
@aegiskit/store-upstash
An atomic, serverless-correct rate-limit store for Aegis, backed by Upstash Redis.
This is the store that makes Aegis rate limiting correct on serverless: the increment is a single atomic Redis op (a Lua INCR + first-hit PEXPIRE), so concurrent function invocations share one counter — unlike an in-process map, which resets per instance and never actually limits.
Install
pnpm add @aegiskit/store-upstash @upstash/redisUsage
import { RateLimiter, RATE_LIMIT_PRESETS } from '@aegiskit/core';
import { createUpstashStore } from '@aegiskit/store-upstash';
import { Redis } from '@upstash/redis';
const limiter = new RateLimiter({
store: createUpstashStore({ redis: Redis.fromEnv() }),
failureMode: 'open', // allow on Redis outage (logged); use 'closed' to deny
});
const { success, retryAfter } = await limiter.limit(userId, RATE_LIMIT_PRESETS.auth);Pass the resulting limiter to secure({ rateLimit: { limiter } }) or secureRoute({ rateLimit: { limiter, rule } }) from @aegiskit/next.
License
MIT
