Backend · Skill

Add Upstash Redis

add-upstash-redis

Adds Upstash Redis over HTTP for a serverless function, with one shared client, cache-aside with a TTL, sliding sessions, and a 429 limit. Use when the user wants Upstash, a Redis cache without a TCP socket, or a session store on the edge.

Works with: Any AI Not yet model-tested; testing Jan 2027

Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works

Install in Claude Code, Cursor or Codex (optional)

Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.

Claude Code (all your projects)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-upstash-redis/raw' -o ~/'.claude/skills/add-upstash-redis/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-upstash-redis/files/LICENSE.txt' -o ~/'.claude/skills/add-upstash-redis/LICENSE.txt'

Cursor (this project)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-upstash-redis/raw' -o '.cursor/skills/add-upstash-redis/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-upstash-redis/files/LICENSE.txt' -o '.cursor/skills/add-upstash-redis/LICENSE.txt'

Codex and other Agent Skills tools (this project)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-upstash-redis/raw' -o '.agents/skills/add-upstash-redis/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-upstash-redis/files/LICENSE.txt' -o '.agents/skills/add-upstash-redis/LICENSE.txt'

Or connect the whole library over MCP

Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):

{
  "mcpServers": {
    "theskillvault": {
      "url": "https://theskillvault.ai/mcp"
    }
  }
}

Upstash Redis speaks HTTP. A short-lived function can call it without a TCP pool. Use it for a cache, a session or a small limit.

When to use

  • A serverless or edge handler needs a shared cache.
  • Sessions must survive a cold start.
  • You want a 429 limit that many instances share.

When not to use

  • The app already has a long-lived TCP Redis client. Keep that client.
  • You need vector search. Use a vector store, not this cache.
  • The limit is part of chatbot abuse control. Use add-chatbot-guardrails-and-rate-limits for that policy.

Steps

  1. Create an Upstash Redis database. Copy the REST URL and the REST token into env vars named UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN. Do not commit them.
  2. Install @upstash/redis. Add @upstash/ratelimit only if you need a limit.
  3. Create one client per module with Redis.fromEnv(). Do not construct it inside the handler.
  4. Cache with a TTL. On a miss, read the source of truth, then set with { ex: seconds }. On a write, update or delete the same key.
  5. For sessions, store an id in an HttpOnly cookie and the payload in Redis under session:<id>. Refresh the TTL on read. Delete the key on sign-out.
  6. For a limit, build one Ratelimit at module scope. slidingWindow is a sound default. Key it by user id when you have one, otherwise by the platform IP. Return 429 when success is false.
  7. Call ping once in a scratch script. You want the string PONG.
import { Redis } from "@upstash/redis";

export const redis = Redis.fromEnv();

export async function getProduct(id: string) {
  const key = `product:${id}`;
  const hit = await redis.get<Product>(key);
  if (hit) return hit;
  const row = await db.products.find(id);
  if (row) await redis.set(key, row, { ex: 600 });
  return row;
}

Gotchas

  • The client already encodes objects. Do not JSON.stringify before set, or the next get will surprise you.
  • A key with no TTL lives until something deletes it. Always pass { ex }.
  • The REST token is a secret. Keep it in .env or the host's secret store. Never send it to the browser.
  • Do not trust a raw forwarded-for header. Use the platform's client IP when the host provides one.
  • On the edge, some limit calls return a pending promise. Wait for it before the isolate exits.
  • KEYS on a large database is a bad idea. Use a known prefix and exact keys.

Portability

Works with any host that can call HTTPS, including Node and edge workers. If you use a long-running server, a TCP client is the usual equivalent.

Done when

  • ping returns PONG from the deployed environment.
  • A second read of a cached key does not hit the database, and the key has a TTL.
  • The REST token is not in git or in client code.
  • A limit, if you added one, returns 429 after the budget and succeeds again later.

Example prompt

"Add Upstash Redis to this serverless route. Cache the product by id for 10 minutes, and keep the REST token in env."

---

Adapted from "upstash-redis" in github/awesome-copilot (MIT, Copyright GitHub, Inc.). See LICENSE.txt.

Bundled files

Licence

Adapted from Upstash (github/awesome-copilot, upstash-redis) (Copyright GitHub, Inc.), MIT License. Adapted by TheSkillVault on 2026-11-10: rewritten as a short build order with smaller original snippets for cache, session and a 429 limit; dropped the long route sample and vendor doc links; added secret handling, gotchas and done-when. Not the original file.

Licence: MIT License. Attribution when you reuse it: Based on work by Upstash (github/awesome-copilot, upstash-redis) (Copyright GitHub, Inc., MIT License), https://github.com/github/awesome-copilot/tree/5269f7ea2d6c3a9bfda5ed878b6726cf509121fd/skills/upstash-redis; adapted by TheSkillVault, https://theskillvault.ai