ekx-upstash-redislisted
Install: claude install-skill Ekinoxis-evm/claude-skills
# Upstash Redis
Our serverless Redis, with `@upstash/ratelimit` on top of it.
Why Upstash and not a normal Redis: it speaks **HTTP**, so it works from Vercel edge
and serverless functions where a persistent TCP connection is not available. A regular
Redis client opens a connection per invocation and exhausts the connection pool under
load — that is the failure `ioredis` has to manage on a long-lived Railway process.
---
## Environment
```bash
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN= # SECRET
```
(`UPSTASH_REDIS_REST_KV_REST_API_URL`/`_TOKEN` also turn up — the names Vercel's KV
integration injects. Same values; prefer the plain pair.)
---
## Client
```ts
import { Redis } from "@upstash/redis";
export const redis = Redis.fromEnv(); // reads the two vars above
```
```ts
await redis.set("price:eth", 3200, { ex: 60 }); // TTL in seconds
const price = await redis.get<number>("price:eth");
```
**Always set a TTL.** Upstash bills per command and per stored byte; keys without
expiry accumulate silently and turn into a monthly line item nobody can attribute.
---
## Rate limiting
```ts
import { Ratelimit } from "@upstash/ratelimit";
const limiter = new Ratelimit({
redis,
limiter: Ratelimit.slidingWindow(10, "60 s"),
analytics: true,
prefix: "gt",
});
export async function POST(req: Request) {
const ip = req.headers.get("x-forwarded-for") ?? "anon";
const { success, reset } = await limiter.limit(ip);
if (!success) {
return new