Azure Managed Redis
Caching · expiration and eviction · invalidation · connection practices · clustering policies · RediSearch vector indexing
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Azure Managed Redis basics
Azure Managed Redis is an in-memory data store based on Redis Enterprise software. It supports Redis version 7.4.x. Four tiers are available.
| Tier | Memory-to-vCPU | Notes |
|---|---|---|
| Memory Optimized | 8:1 | High memory, lower throughput; lower price point, good for dev and test. |
| Balanced | 4:1 | Standard workloads: balance of memory and compute. |
| Compute Optimized | 2:1 | Performance-intensive workloads that need maximum throughput. |
| Flash Optimized | - | Moves less frequently accessed data from RAM to NVMe storage. No search (so no vector search), no active geo-replication, no non-clustered instances. |
- High availability can be disabled to lower the price, but that results in data loss and downtime. Disable it only for dev and test; the data isn't replicated and the instance is unavailable during maintenance.
- TLS is required by default (versions 1.2 and 1.3). Connect by hostname (
<DNS name>.<Azure region>.redis.azure.net), not by IP address: the IP can change after a scale operation. - Keep the client in the same region as the cache; a cross-region connection increases latency and reduces reliability.
- Microsoft Entra ID authentication is enabled by default when you create the cache.
| Python connection (redis-py) | Detail |
|---|---|
| Packages | redis, redis-entraid, azure-identity |
| Port | 10000 for Azure Managed Redis and Enterprise caches; 6380 for Azure Cache for Redis. |
| Credential | create_from_default_azure_credential(("https://redis.azure.com/.default",),) |
| Client | redis.Redis(host=redis_host, port=redis_port, ssl=True, decode_responses=True, credential_provider=credential_provider) |
| Operations | r.ping(), r.set("Message", "Hello from Azure Managed Redis!"), r.get("Message") |
| Access | You must add yourself (or a system principal) as a Redis user on the cache. |
Caching, expiration and invalidation
Cache-aside
- The application tries to read the item from the cache.
- On a cache miss, it reads the item from the data store.
- It adds the item to the cache and returns it.
- On an update, it writes to the data store and then invalidates the cached item. The next read reloads it.
- Cache-aside doesn't guarantee consistency between the data store and the cache. Between a write and the next read a reader can see a cache miss or briefly stale data. Write-through updates the store and the cache in the same write.
- Match the expiration period to the access pattern: too short and the app keeps reloading from the data store; too long and the cache goes stale.
- When the cache exceeds its size limit it evicts data; most caches use a least-recently-used policy.
- A shared cache fits many app instances; a local in-memory cache is private to one instance and can drift out of sync.
| Memory setting | Rule |
|---|---|
| Default eviction policy | volatile-lru: only keys with a TTL (for example set with EXPIRE) can be evicted. If no keys have a TTL, nothing is evicted. |
| Allow any key to be evicted | allkeys-lru |
| Expiration | Set an expiration on keys. It removes keys proactively instead of waiting for memory pressure; eviction under pressure adds load to the server. |
| Expiration cost | Keys with a TTL use extra memory for expiration bookkeeping. |
| Used Memory metric | Includes all shards and, with high availability, primary and replica memory: it can be about twice the dataset size. Alert on Used Memory Percentage; consider scaling if it stays over 75%. |
| Key memory | MEMORY USAGE <your_key_name> returns the total bytes consumed by a key. |
- Redis data is ephemeral by default. For data-loss sensitivity enable data persistence (a quick recovery point on a managed disk you can't access) or take backups.
- Don't use persistence for periodic backups. Use import/export: it exports RDB copies to a storage account, from the portal, CLI, PowerShell or SDKs.
Client and server best practices
| Practice | Detail |
|---|---|
| Value size | Prefer more keys and smaller values; keep values under 100 kB. Large responses can make later pipelined requests time out. |
| Large responses | Break data into smaller values, use a VM with more bandwidth, or use more connection objects round-robin. |
| Pipelining | Choose a client that supports it for best throughput. |
| Expensive commands | Avoid commands such as KEYS. Redis is single-threaded; a long-running command blocks other requests. |
| Retries | Retry commands with exponential backoff. |
| Timeouts | Connect timeout of five seconds; command timeout initially under five seconds, tuned to your value sizes. |
| Connection spikes | Creating and closing connections is expensive and new connections are rate limited: stagger reconnects. |
| Linux clients | Recommended net.ipv4.tcp_retries2 = 5 (default TCP settings can cause connection failures for 13 minutes or more). |
| Monitoring | Alert on Used Memory Percentage, CPU and Connected Clients above 75%; keep server load under 80%. |
Clustering policies
| Policy | Behavior | RediSearch |
|---|---|---|
| OSS | Client connects directly to shards (needs Redis Cluster API support). Initial connection on port 10000; 85XX ports for nodes, don't hardcode them. Generally the lowest latency and best throughput. | Not supported |
| Enterprise | Single endpoint; a proxy node routes requests. Looks non-clustered, but the proxy can be a bottleneck. | Supported |
| Non-clustered | No sharding; only for caches of 25 GB or smaller; not as performant. To scale up you must first change the policy. | Supported |
CROSSSLOTerrors can occur on multi-key commands. With the Enterprise policy onlyDEL,MSET,MGET,EXISTS,UNLINKandTOUCHare allowed across slots.- A non-clustered cache with geo-replication enabled can't change its clustering policy after creation.
Vector indexing with RediSearch
- Vector search needs the RediSearch module. Enable it when you create the cache: modules can't be added later and you can't load or update them manually.
- RediSearch: Memory Optimized, Balanced and Compute Optimized yes; Flash Optimized no. Clustering policy: Enterprise or Non-clustered, not OSS.
- Only RediSearch and RedisJSON work with active geo-replication. RedisJSON is available on all four tiers. RedisBloom adds bloom filter, cuckoo filter, count-min sketch and top-k.
- Store vectors in hashes or JSON documents, with metadata (document ID, title, source URL, category, timestamp, tenant ID, access-control fields) so queries can filter and return sources.
- Use one embedding model per vector index; the index schema, dimensions and distance metric must match the model.
- Size the cache for vector data and index overhead.
| Term | Meaning |
|---|---|
| FLAT | Exact brute-force index; for smaller datasets or exhaustive search. |
| HNSW | Approximate nearest-neighbor index (Hierarchical Navigable Small World graphs); larger datasets where latency matters more than exhaustive precision. |
| KNN | Returns the top K most similar vectors. |
| ANN | Approximate nearest neighbors: trades some precision for lower latency and less compute. |
| Distance metrics | L2, COSINE, IP |
| Hybrid search | Metadata filters narrow the candidates before or during vector comparison, for example only documents the current user may access. |
| Semantic caching | Reuse a cached LLM completion when a new prompt is semantically similar, to reduce LLM cost and latency. |
Exam Tips
Tick each tip once you can answer it without looking.
“Data changed in the database; cache must not serve old value” → Cache-aside: write to the data store, then invalidate the cached item. Trap: Cache-aside doesn't guarantee consistency; a reader may briefly see stale data or a cache miss.
“Cache-aside expiration setting” → Match it to the access pattern. Trap: Too short: constant reloads from the data store. Too long: stale data.
“Default eviction policy of Azure Managed Redis” → volatile-lru: only keys with a TTL are eligible. Trap: With no TTLs set nothing is evicted; use allkeys-lru if any key may be evicted.
“Avoid eviction load under memory pressure” → Set an expiration on keys. Trap: TTL keys use extra memory for bookkeeping, but expiration removes keys proactively.
“Used Memory shows about 20 GB for a 10 GB dataset” → High availability: the metric includes primary and replica shards. Trap: The metric counts replica memory too. Alert on Used Memory Percentage (consistently over 75%: consider scaling).
“Python port for Azure Managed Redis” → 10000 (ssl=True, Entra credential provider). Trap: 6380 is the port for Azure Cache for Redis instances.
“Periodic backups of cache data to a storage account” → Import/export (RDB). Trap: Data persistence is a recovery point on a disk you can't access, not for periodic backups.
“Lower the price by turning off high availability” → Only for dev and test. Trap: Without HA data isn't replicated: data loss and downtime during maintenance.
“Timeouts after one very large response” → Smaller values, more bandwidth, or more connection objects. Trap: Avoid KEYS and other expensive commands; Redis is single-threaded.
“Vector search on Azure Managed Redis” → Enable the RediSearch module at creation. Trap: Modules can't be added or loaded after the instance exists.
“Clustering policy for RediSearch on a 60 GB cache” → Enterprise. Trap: OSS isn't supported with RediSearch; Non-clustered is only for 25 GB or smaller.
“Cheapest large tier but need vector search” → Not Flash Optimized: use Memory Optimized, Balanced or Compute Optimized. Trap: Flash Optimized has no search functionality.
“Exact search vs. approximate search” → FLAT is exact brute force; HNSW is approximate and faster for large sets. Trap: ANN trades some precision for lower latency; KNN just returns the top K.
“RAG search limited to what the current user may read” → Store access-control or tenant metadata with each vector and filter on it. Trap: Without metadata the query can't narrow candidates.
“Cut LLM cost by reusing answers to similar prompts” → Semantic caching with vector similarity. Trap: Use it only when the data supports semantic equivalence and holds no private or sensitive data.
Sources
- What is Azure Managed Redis?
- Azure Managed Redis architecture
- Best practices for memory management
- Best practices for development
- Best practices for connection resilience
- Best practices for server load
- Quickstart: Create a Python app with Azure Managed Redis
- Using Redis modules with Azure Managed Redis
- About vector embeddings and vector search in Azure Managed Redis
- Cache-Aside pattern
Checked against Microsoft Learn on November 13, 2026.