{"name":"add-upstash-redis","description":"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.","category":"backend","tags":["redis","nodejs","api"],"models":["any"],"proven":false,"passing_families":0,"model_testing":"Not yet model-tested; testing Jan 2027","url":"https://theskillvault.ai/skills/add-upstash-redis","api_url":"https://theskillvault.ai/api/skills/add-upstash-redis","raw_url":"https://theskillvault.ai/api/skills/add-upstash-redis/raw","body":"# Add Upstash Redis\n\nUpstash 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.\n\n## When to use\n- A serverless or edge handler needs a shared cache.\n- Sessions must survive a cold start.\n- You want a 429 limit that many instances share.\n\n## When not to use\n- The app already has a long-lived TCP Redis client. Keep that client.\n- You need vector search. Use a vector store, not this cache.\n- The limit is part of chatbot abuse control. Use add-chatbot-guardrails-and-rate-limits for that policy.\n\n## Steps\n1. 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.\n2. Install `@upstash/redis`. Add `@upstash/ratelimit` only if you need a limit.\n3. Create one client per module with `Redis.fromEnv()`. Do not construct it inside the handler.\n4. 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.\n5. 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.\n6. 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.\n7. Call `ping` once in a scratch script. You want the string `PONG`.\n\n```ts\nimport { Redis } from \"@upstash/redis\";\n\nexport const redis = Redis.fromEnv();\n\nexport async function getProduct(id: string) {\n  const key = `product:${id}`;\n  const hit = await redis.get<Product>(key);\n  if (hit) return hit;\n  const row = await db.products.find(id);\n  if (row) await redis.set(key, row, { ex: 600 });\n  return row;\n}\n```\n\n## Gotchas\n- The client already encodes objects. Do not `JSON.stringify` before `set`, or the next `get` will surprise you.\n- A key with no TTL lives until something deletes it. Always pass `{ ex }`.\n- The REST token is a secret. Keep it in `.env` or the host's secret store. Never send it to the browser.\n- Do not trust a raw forwarded-for header. Use the platform's client IP when the host provides one.\n- On the edge, some limit calls return a `pending` promise. Wait for it before the isolate exits.\n- `KEYS` on a large database is a bad idea. Use a known prefix and exact keys.\n\n## Portability\nWorks 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.\n\n## Done when\n- `ping` returns `PONG` from the deployed environment.\n- A second read of a cached key does not hit the database, and the key has a TTL.\n- The REST token is not in git or in client code.\n- A limit, if you added one, returns 429 after the budget and succeeds again later.\n\n## Example prompt\n\"Add Upstash Redis to this serverless route. Cache the product by id for 10 minutes, and keep the REST token in env.\"\n\n---\nAdapted from \"upstash-redis\" in github/awesome-copilot (MIT, Copyright GitHub, Inc.). See LICENSE.txt.","files":["LICENSE.txt"],"license":"MIT","license_name":"MIT License","license_url":"https://opensource.org/license/mit","attribution":"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","install":{"claude_code":"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":"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'","agents":"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'","mcp_url":"https://theskillvault.ai/mcp","cursor_mcp_deeplink":"cursor://anysphere.cursor-deeplink/mcp/install?name=theskillvault&config=eyJ1cmwiOiJodHRwczovL3RoZXNraWxsdmF1bHQuYWkvbWNwIn0%3D","mcp_config":{"mcpServers":{"theskillvault":{"url":"https://theskillvault.ai/mcp"}}}},"bundles":[],"tested_on":[{"family":"chatgpt","name":"ChatGPT","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"claude","name":"Claude","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"gemini","name":"Gemini","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"grok","name":"Grok","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"llama","name":"Llama","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"deepseek","name":"DeepSeek","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"mistral","name":"Mistral","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"qwen","name":"Qwen","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"kimi","name":"Kimi K","outcome":null,"date":null,"source":null,"counts":false,"stale":false}],"proven_rule":{"threshold":5,"window_days":365,"computed_at":"2026-11-29T03:42:30.374Z"}}