Redis Project
Language: Redis, TypeScript October 1, 2025
Instruction file for Redis caching and data structures.
---
applyTo: "**/*.ts, **/*.js, **/cache/**, **/redis/**"
---
# Redis Development Instructions (2025)
_Last updated: October 2025_
- Always use the fetch tool to look up the latest Redis documentation: https://redis.io/docs
- Use Redis for caching, session storage, and real-time features
- Leverage Redis data structures: strings, hashes, lists, sets, sorted sets
- Implement proper key naming conventions and expiration strategies
- Use Redis pipelines for batching commands
- Consider Redis Cluster for horizontal scaling
**Core Principles:**
- Use descriptive key naming with colons: `user:123:profile`
- Set TTL (Time To Live) on cached data to prevent stale data
- Use appropriate data structures for use cases
- Implement proper error handling and connection management
- Use connection pooling for production applications
- Monitor memory usage and eviction policies
**Data Structures:**
- Use strings for simple key-value storage
- Use hashes for objects with multiple fields
- Use lists for queues and stacks (LPUSH/RPOP, LPUSH/LPOP)
- Use sets for unique collections and set operations
- Use sorted sets for leaderboards and time-series data
**Caching Patterns:**
- Implement cache-aside pattern for lazy loading
- Use write-through caching for consistency
- Set appropriate TTL based on data freshness requirements
- Use cache stampede prevention (lock, probabilistic early expiration)
- Implement cache warming for critical data
**Performance:**
- Use pipelining to reduce round-trips
- Implement Lua scripts for atomic complex operations
- Use SCAN instead of KEYS for production key iteration
- Set maxmemory and eviction policies (LRU, LFU)
- Monitor slow commands with SLOWLOG
**Pub/Sub:**
- Use Redis Pub/Sub for real-time messaging
- Implement proper subscriber patterns
- Consider Redis Streams for message queuing with persistence
- Use keyspace notifications for event-driven patterns
**Best Practices:**
- Use ioredis or node-redis client for Node.js
- Implement graceful connection handling
- Use transactions with MULTI/EXEC when needed
- Implement proper key expiration strategies
- Monitor Redis with INFO command and monitoring tools
**Summary:**
> For all Redis work, always use the fetch tool to look up the latest documentation from https://redis.io/docs. Build high-performance caching and real-time features. Redis Cache Database Backend Performance