Redis is an in-memory data store used as a cache, message broker, and session store. It stores key-value pairs with sub-millisecond access times.
Cache-aside pattern: app checks Redis first, falls back to database on miss, then caches the result. Most common pattern for read-heavy workloads.
Write-through: write to cache and database simultaneously. Ensures consistency but adds write latency.
Cache invalidation: delete keys when data changes. TTL (time-to-live) expires stale data automatically. Use cache tags for group invalidation.
Redis data structures for caching: strings for simple values, hashes for objects, lists for queues, sorted sets for leaderboards.
Session storage: store user sessions in Redis for fast access across server instances. Redis persistence options (RDB, AOF) prevent data loss on restart.
Pub/Sub enables real-time messaging between services. Redis Streams handle event sourcing and message queues.