Implement Azure Managed Redis caching, expiration, and invalidation
Unlock the complete study guide + 1,040 practice questions across 16 full exams.
Bundled into the existing Developing AI Cloud Solutions on Azure premium course — no separate purchase.
14-day money-back guarantee — no questions asked.
Included in this chapter:
- Two ways a key leaves the cache
- The tier sets capacity, the policy sets your client
- Setting a time to live without losing it
- How Redis actually removes an expired key
- Eviction: maxmemory-policy and the volatile-lru default
- Cache-aside: read on miss, invalidate on write
- When a hot key expires: the cache stampede
- Keyspace notifications and their delivery guarantee
- Exam-pattern recognition
Eviction policies, and what each one does when the instance is full
| maxmemory-policy | Which keys are candidates | How the victim is chosen | Reach for it when |
|---|---|---|---|
| volatile-lru (the Azure Managed Redis default) | Only keys that have a TTL set | Least recently used among those candidates | Every cached entry carries an expiry and you want keys without one treated as pinned. If no key has a TTL, nothing is eligible and the instance stops accepting writes instead. |
| allkeys-lru | Every key in the instance | Least recently used across the whole keyspace | The instance is purely a cache and you would rather lose the coldest entry than fail a write. Microsoft names this as the alternative when you want any key to be evictable under pressure. |
| volatile-ttl | Only keys that have a TTL set | The one closest to expiring | Entries carry meaningfully different lifetimes and shedding the soonest-to-die first is closest to what would have happened anyway. |
| volatile-random | Only keys that have a TTL set | Picked at random among those candidates | Recency carries no signal for your workload and you want the cheapest possible choice. |
| noeviction | None | Nothing is removed; writes fail instead | The instance holds data you must not silently lose, and you would rather see an out-of-memory error on the write path than discover a key vanished. |
Decision tree
Cheat sheet
Unlock with Premium — includes all practice exams and the complete study guide.
References
- Caching guidance Well-Architected
- What is Azure Managed Redis?
- Azure Managed Redis architecture
- Use Microsoft Entra for cache authentication with Azure Managed Redis
- Quickstart: create a Python app with Azure Managed Redis
- Connect redis-py to Azure Managed Redis
- Best practices using client libraries with Azure Managed Redis
- Multi-key operations
- SET command reference
- EXPIRE command reference
- TTL command reference
- Redis keyspace notifications
- Best practices for memory management for Azure Managed Redis
- Cache-Aside pattern Well-Architected
- UNLINK command reference
- Redis cache-aside with redis-py
- Enable Redis keyspace notifications in Azure Managed Redis (preview)