MR
Mayur Rathi
@github
⭐ 47.3k GitHub stars

Upstash-Redis

Upstash-Redis is an code AI skill with a core value of >. It helps developers solve real-world problems in the code domain, boosting efficiency, automating repetitive tasks, and optimizing workflows.

>

Last verified on: 2026-10-06

Quick Facts

Category code
Works With GitHub Copilot, Claude
Source sickn33/antigravity-awesome-skills
Stars ⭐ 47.3k
Last Verified 2026-10-06
Risk Level Low
mkdir -p ./skills/upstash-redis && curl -sfL https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/skills/upstash-redis/SKILL.md -o ./skills/upstash-redis/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# Upstash Redis Skill


This skill covers the three things serverless apps most often need Redis for:

caching, sessions, and rate limiting. The client talks to Redis over HTTP, so

it works where a long-lived TCP connection does not (edge middleware, short

lived functions). Follow the steps in order; each ends with a checkpoint.


Requirements and limitations


- An Upstash Redis database (hosted service; usage-based pricing with a free

tier). Credentials are a REST URL and token from the database page.

- Environment variables `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`.

- Every command is an HTTP request. Batch with `pipeline()` or `MGET`/`MSET`

when you issue many commands per request; avoid `KEYS *` in production.

- Values are serialized automatically (objects, arrays, numbers round-trip).

Do not `JSON.stringify` before `set` or `parseInt` after `get`.


Step 1 — Install and create one client per module


bash
npm install @upstash/redis @upstash/ratelimit

ts
// lib/redis.ts
import { Redis } from "@upstash/redis";

// Reads UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN
export const redis = Redis.fromEnv();

Create the client at module scope, not inside the request handler, so

ephemeral caches and pipelines can be reused across invocations.


> **Checkpoint**: `await redis.ping()` returns `"PONG"`.


Step 2 — Cache-aside with TTL


ts
import { redis } from "@/lib/redis";

type User = { id: string; name: string; plan: "free" | "pro" };

export async function getUser(userId: string): Promise<User | null> {
  const key = `user:${userId}`;
  const cached = await redis.get<User>(key);
  if (cached) return cached;

  const user = await db.users.findById(userId); // your data source
  if (user) await redis.set(key, user, { ex: 3600 }); // 1 hour TTL
  return user;
}

export async function updateUser(userId: string, patch: Partial<User>) {
  const user = await db.users.update(userId, patch);
  await redis.set(`user:${userId}`, user, { ex: 3600 }); // write-through
  return user;
}

export async function deleteUser(userId: string) {
  await db.users.delete(userId);
  await redis.del(`user:${userId}`); // invalidate
}

Always set a TTL on cache entries; namespace keys (`user:123`, `session:abc`).


> **Checkpoint**: second call to `getUser` returns without hitting the database

> and `await redis.ttl("user:123")` is positive.


Step 3 — Sessions with sliding expiration


ts
import { redis } from "@/lib/redis";

const SESSION_TTL = 60 * 60 * 24; // 24 hours

export async function createSession(userId: string, data: Record<string, unknown>) {
  const sessionId = crypto.randomUUID();
  await redis.set(`session:${sessionId}`, { userId, ...data, createdAt: Date.now() }, { ex: SESSION_TTL });
  return sessionId;
}

export async function getSession<T = Record<string, unknown>>(sessionId: string) {
  const session = await redis.get<T>(`session:${sessionId}`);
  if (session) await redis.expire(`session:${sessionId}`, SESSION_TTL); // slide
  return session;
}

export async function destroySession(sessionId: string) {
  await redis.del(`session:${sessionId}`);
}

Store the session id in an `HttpOnly; Secure; SameSite` cookie; never put the

Redis token in client code.


> **Checkpoint**: `getSession` after `createSession` returns the object with

> `userId`; after `destroySession` it returns `null`.


Step 4 — Rate limiting a route handler


ts
// app/api/search/route.ts (Next.js App Router; same pattern for any fetch handler)
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";

const ratelimit = new Ratelimit({
  redis: Redis.fromEnv(),
  limiter: Ratelimit.slidingWindow(10, "10 s"), // 10 requests per 10 seconds
  prefix: "ratelimit:search", // isolate keys per limiter
});

export async function POST(request: Request) {
  const ip = request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ?? "anonymous";
  const { success, limit, remaining, reset } = 

🎯 Best For

  • GitHub Copilot users
  • Claude users
  • Software engineers
  • Development teams
  • Tech leads

💡 Use Cases

  • Code quality improvement
  • Best practice enforcement

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open GitHub Copilot or Claude and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply Upstash-Redis to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Is Upstash-Redis compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for Upstash-Redis?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install Upstash-Redis?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/upstash-redis/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills