Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aiskillstore avatar

Redis Patterns

  • 1 installs
  • 404 repo stars
  • Updated August 5, 2026
  • aiskillstore/marketplace

redis-patterns is a skill that provides Upstash Redis patterns for caching, rate limiting, sessions, and pub/sub in TypeScript.

About

This skill provides Upstash Redis patterns for caching and rate limiting in TypeScript. It covers basic caching with TTL, cache invalidation, sliding-window rate limiting, session storage, pub/sub, leaderboards, and the cache-aside pattern. A developer uses it when adding Redis-backed caching or rate limits to a Node or Next.js backend.

  • Upstash Redis caching and rate-limiting patterns
  • Session storage, pub/sub, and leaderboard recipes
  • Cache-aside and TTL invalidation examples in TypeScript

Redis Patterns by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #765 of 911 Databases skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
At a glance

redis-patterns capabilities & compatibility

Requires Upstash Redis REST URL and token (UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN).

Capabilities
database · api development
Works with
redis
Use cases
database · api development
Pricing
Bring your own API key
From the docs

What redis-patterns says it does

Upstash Redis patterns for caching and rate limiting.
SKILL.md
limiter: Ratelimit.slidingWindow(10, '10 s'), // 10 requests per 10 seconds
SKILL.md
npx skills add https://github.com/aiskillstore/marketplace --skill redis-patterns

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
repo stars404
Last updatedAugust 5, 2026
Repositoryaiskillstore/marketplace

What it does

Add Upstash Redis caching, rate limiting, sessions, or pub/sub to a Node or Next.js backend.

Who is it for?

Developers adding Redis-backed caching or rate limiting with Upstash in TypeScript.

Skip if: Self-hosted Redis clients other than Upstash, or non-JavaScript stacks.

When should I use this skill?

Adding Redis caching, rate limiting, session storage, or pub/sub to a backend.

What you get

Produces Upstash Redis code for caching, rate limiting, sessions, pub/sub, and leaderboards.

  • Redis cache helpers
  • rate limiter
  • session store

By the numbers

  • 8 Redis pattern sections (caching, invalidation, rate limiting, sessions, pub/sub, leaderboard, cache-aside)
  • sliding-window limit of 10 requests per 10 seconds

Files

SKILL.mdMarkdownGitHub ↗

Upstash Redis Patterns

Setup

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

export const redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL!,
  token: process.env.UPSTASH_REDIS_REST_TOKEN!,
});

Basic Caching

// Cache with TTL
async function getCachedUser(id: string): Promise<User | null> {
  const cacheKey = `user:${id}`;

  // Try cache first
  const cached = await redis.get<User>(cacheKey);
  if (cached) return cached;

  // Fetch from DB
  const user = await db.query.users.findFirst({
    where: eq(users.id, id),
  });

  if (user) {
    // Cache for 5 minutes
    await redis.setex(cacheKey, 300, user);
  }

  return user;
}

Cache Invalidation

// Invalidate on update
async function updateUser(id: string, data: UpdateUserInput): Promise<User> {
  const user = await db.update(users)
    .set(data)
    .where(eq(users.id, id))
    .returning();

  // Invalidate cache
  await redis.del(`user:${id}`);

  // Also invalidate list caches
  await redis.del('users:list');

  return user[0];
}

Rate Limiting

import { Ratelimit } from '@upstash/ratelimit';

const ratelimit = new Ratelimit({
  redis,
  limiter: Ratelimit.slidingWindow(10, '10 s'), // 10 requests per 10 seconds
  analytics: true,
});

// In API route or middleware
export async function POST(request: Request) {
  const ip = request.headers.get('x-forwarded-for') ?? 'anonymous';
  const { success, limit, reset, remaining } = await ratelimit.limit(ip);

  if (!success) {
    return new Response('Too Many Requests', {
      status: 429,
      headers: {
        'X-RateLimit-Limit': limit.toString(),
        'X-RateLimit-Remaining': remaining.toString(),
        'X-RateLimit-Reset': reset.toString(),
      },
    });
  }

  // Process request...
}

Session Storage

interface Session {
  userId: string;
  expiresAt: number;
}

async function createSession(userId: string): Promise<string> {
  const sessionId = crypto.randomUUID();
  const session: Session = {
    userId,
    expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000, // 7 days
  };

  await redis.setex(`session:${sessionId}`, 7 * 24 * 60 * 60, session);
  return sessionId;
}

async function getSession(sessionId: string): Promise<Session | null> {
  return await redis.get<Session>(`session:${sessionId}`);
}

async function deleteSession(sessionId: string): Promise<void> {
  await redis.del(`session:${sessionId}`);
}

Pub/Sub for Real-time

// Publisher
async function publishEvent(channel: string, data: unknown): Promise<void> {
  await redis.publish(channel, JSON.stringify(data));
}

// Usage
await publishEvent('user:updates', { userId: '123', action: 'updated' });

Leaderboard

// Add score
await redis.zadd('leaderboard', { score: 100, member: 'user:123' });

// Get top 10
const topUsers = await redis.zrevrange('leaderboard', 0, 9, { withScores: true });

// Get user rank
const rank = await redis.zrevrank('leaderboard', 'user:123');

Cache Patterns

// Cache-aside pattern
async function getData<T>(
  key: string,
  fetcher: () => Promise<T>,
  ttl: number = 300
): Promise<T> {
  const cached = await redis.get<T>(key);
  if (cached) return cached;

  const data = await fetcher();
  await redis.setex(key, ttl, data);
  return data;
}

// Usage
const user = await getData(
  `user:${id}`,
  () => db.query.users.findFirst({ where: eq(users.id, id) }),
  300
);

Related skills

FAQ

Which Redis does this use?

Upstash Redis via the @upstash/redis REST client.

How is rate limiting done?

With @upstash/ratelimit using a sliding-window limiter, for example 10 requests per 10 seconds.

Databasesdatabases

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.