Home › Redis / Valkey › Redis Windsurf rules

Redis Windsurf rules

Windsurf rules for using Redis (or Valkey) as cache, rate limiter, and queue: key design, TTLs, and atomicity.

WindsurfRedis / Valkey

How to use

Save this as .windsurf/rules/redis.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.windsurf/rules/redis.mdDownload  
---
trigger: model_decision
description: Apply when code reads or writes Redis/Valkey: caching, sessions, rate limits, queues, or pub/sub.
---

# Redis / Valkey

## Keys
- Namespaced, colon-separated keys with a version: `app:v1:user:{id}:profile`. Keep the scheme in one `keys.ts`/`keys.py` module.
- Every cache key has a TTL (`SET key val EX 300`). Add jitter to TTLs to avoid stampedes on expiry.
- Never use `KEYS *` in app code; use `SCAN` with `MATCH` for maintenance only.

## Patterns
- Cache-aside: read cache, on miss load from the DB and set with TTL. Invalidate (delete) on write, don't update in place. The database stays the source of truth.
- Rate limiting: atomic `INCR` + `EXPIRE` in a `MULTI` or a Lua script, or a sliding window with sorted sets.
- Locks: `SET lock:x token NX PX 30000` and release only if the token matches (Lua). Prefer avoiding distributed locks.
- Queues: use Streams (`XADD`/`XREADGROUP`/`XACK`) or the job library in use (BullMQ, RQ, Sidekiq) instead of raw lists.
- Pipeline batches of commands; avoid one round trip per item.

## Data
- Store compact JSON or hashes; keep values small (< 100 KB). Don't keep unbounded lists or sets without trimming.
- Don't store secrets or PII without a clear TTL and need.

## Ops
- One shared client with reconnect; set command timeouts. Handle Redis being down by falling back to the DB where possible.

More: all Redis / Valkey rules · all Windsurf rules

Related rules

MongoDB Windsurf rules

Windsurf rules for MongoDB 8 apps with the Node.js driver: schema design, indexes, aggregation, and transactions.

WindsurfMongoDB

Convex backend rules

Cursor rules for Convex backends: schema, validated queries/mutations/actions, indexes, and auth checks.

CursorConvex

Drizzle ORM rules

Cursor rules for Drizzle ORM with Postgres or SQLite: schema files, drizzle-kit migrations, and type-safe queries.

CursorDrizzle ORM

Firebase (modular SDK) rules

Cursor rules for Firebase web apps with the modular v11+ SDK, Firestore security rules, and emulator tests.

CursorFirebase

Mongoose (MongoDB ODM) rules

Cursor rules for Mongoose 8 with TypeScript: typed schemas, indexes, lean queries, validation, and transactions.

CursorMongoDB

Neon serverless Postgres CLAUDE.md

CLAUDE.md for apps on Neon serverless Postgres: pooled connections, the serverless driver, branches, and migrations.

Claude Code (CLAUDE.md)Neon Postgres

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.