Redis Caching
Redis is an in-memory data structure store used as a database, cache, and message broker.
Key Concepts
Data Types
- Strings: Simple key-value pairs
- Hashes: Field-value pairs within a key
- Lists: Ordered collections of strings
- Sets: Unordered collections of unique strings
- Sorted Sets: Sets with scores for ordering
- Streams: Log-like data structures (Redis 5.0+)
Caching Patterns
- Cache-Aside: Application manages cache
- Write-Through: Write to cache and database simultaneously
- Write-Behind: Write to cache first, then database
- Refresh-Ahead: Proactively refresh cache before expiration
Common Interview Questions
- What are the advantages of Redis over other caching solutions?
- Explain Redis persistence options (RDB vs AOF)
- How does Redis handle memory management?
- What is Redis clustering and how does it work?
- Explain Redis pub/sub mechanism
- How to implement distributed locking with Redis?
- What are Redis transactions and how do they work?
- How to handle cache invalidation strategies?
- Explain Redis data eviction policies
- How to implement rate limiting with Redis?
- What is Redis Sentinel and its purpose?
- How to handle Redis failover scenarios?