← ClaudeAtlas

redis-patternslisted

Use when using Redis in a Laravel app — caching strategies, atomic/distributed locks, rate limiting, stampede protection, pub/sub, pipelines, and key/TTL design beyond raw query tuning.
pekral/cursor-rules · ★ 5 · API & Backend · score 77
Install: claude install-skill pekral/cursor-rules
# Redis Patterns ## Constraints - Apply `@rules/laravel/laravel.mdc` — use the framework's facades (`Cache`, `RateLimiter`, `Redis`), not a raw client. - Apply `@rules/laravel/queue-debouncing.mdc` for queue/job coalescing concerns when Redis backs the queue. - Cross-link `@rules/sql/optimalize.mdc` (DB-level caching) — Redis caching sits in front of the query tuning that rule owns; cache the result, do not paper over an unindexed query. - `final` classes, `declare(strict_types=1)`, Pest tests (use the `array` cache driver in tests unless asserting Redis-specific behavior). - Always set a TTL. Keys without expiry accumulate and cause memory pressure. ## Use when - Adding caching, rate limiting, distributed coordination, or pub/sub to a Laravel app. - Choosing a cache strategy, protecting a cold cache from stampede, or designing key/TTL conventions. - Configuring Redis as the session, cache, or queue store. Use Laravel facades throughout. Reach for raw `Redis::command(...)` only for structures the Cache abstraction does not expose (sorted sets, streams). ## Caching Strategies ### Cache-Aside (default for read-heavy data) ```php $product = Cache::remember("product:{$id}", now()->addMinutes(10), fn () => Product::findOrFail($id), ); ``` `remember()` is read-through cache-aside: returns the cached value or runs the closure, stores it, and returns it. Use `rememberForever()` only with an explicit invalidation path. ### Write-Through (consistency required) ```php $prod