Skip to content
Back to skills

Redis Patterns

ASecurity

Use Redis correctly for caching, rate limits, locks, queues and sessions, with expiry and failure handling

  • 7 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 30, 2026
ai-agentsdatabasebackendperformance

Works with

  • cli

Security analysis

A100/100

Scanned November 30, 2026

npx -y skills add ansh44233/forge --skill redis-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Redis Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Redis Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ansh44233-redis-patterns/badge)](https://www.skillsdirectory.com/skills/ansh44233-redis-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
description: Use Redis correctly for caching, rate limits, locks, queues and sessions, with expiry and failure handling
profile: standard
tags: database, backend, performance, caching
---

# Redis patterns

Use when adding or changing Redis usage.

## Keys
- Namespace keys (`app:user:123:profile`) and give every cache key a TTL. Keys without expiry are a memory leak.
- Keep values small. Large blobs block the single-threaded server and the network.
- Avoid `KEYS *` in production; use `SCAN`.

## Caching
- Cache-aside: read Redis, fall back to the database, then set with a TTL. Invalidate on write, or use short TTLs where staleness is acceptable.
- Prevent stampedes: add jitter to TTLs and let one request recompute while others serve stale data or wait.

## Rate limiting
Use atomic operations: `INCR` with `EXPIRE` in a `MULTI`, or a Lua script for sliding windows. Never read-then-write from the client.

## Locks
`SET key token NX PX ttl` with a unique token. Release with a Lua script that deletes only if the token matches. Locks expire, so the protected work must be idempotent or fenced.

## Queues and streams
Use Streams with consumer groups (`XREADGROUP`, `XACK`) for at-least-once processing. Handle pending entries after crashes, and make consumers idempotent.

## Failure
- Treat Redis as optional for caches: time out fast and fall back to the source.
- Know the persistence settings before storing anything you cannot rebuild.

## Verify
Tests for cache hits, misses and invalidation; a concurrency test for locks and rate limits; check memory with `INFO memory` under load.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.