Last updated: May 2026
Azure DatabasesIntermediateAZ-104⏱ 11 min read

Azure Cache for Redis

Azure Cache for Redis is a fully managed in-memory data store based on the open-source Redis project. It provides sub-millisecond response times — dramatically faster than any disk-based database. Redis is the standard solution for caching, session management, real-time leaderboards, pub/sub messaging, and any scenario where you need blazing-fast data access.

What you'll learn What Redis is and when to use it · Azure Cache for Redis tiers · Redis data structures · Caching patterns (cache-aside, write-through) · Session state management · Pub/Sub · Persistence options · Geo-replication · Security and private endpoints

What is Redis?

Redis (Remote Dictionary Server) is an in-memory data structure store. All data lives in RAM — making it orders of magnitude faster than disk-based databases. Key characteristics:

  • Sub-millisecond latency — Reads and writes typically <1ms
  • Rich data structures — Strings, lists, sets, sorted sets, hashes, streams
  • Volatile data option — TTL (time-to-live) on keys — automatic expiry
  • Atomic operations — Operations are atomic, avoiding race conditions
  • Pub/Sub — Real-time messaging between applications
⚠️
Not a Primary Database Redis is designed as a cache or secondary data store — not as your primary database (unless you configure persistence and are comfortable with the constraints). Always have a durable primary database (SQL, Cosmos DB, etc.) and use Redis as a cache in front of it.

Azure Cache for Redis Tiers

TierCache SizeHAClusteringBest For
Basic250 MB – 53 GB❌ No❌ NoDev/test only — no SLA
Standard250 MB – 53 GB✅ Primary + replica❌ NoProduction caching
Premium6 GB – 1.2 TB✅ Yes✅ Up to 10 shardsLarge caches, clustering, VNet, persistence
Enterprise12 GB – 2 TB✅ Yes✅ Active geo-replicationEnterprise, active-active geo, RediSearch, RedisBloom
Enterprise Flash300 GB – 13 TB✅ Yes✅ YesVery large caches using SSD extension

Redis Data Structures

TypeUse CaseExample
StringSimple key-value, counters, cached HTMLuser:1234:name = "Priya"
HashObject properties (user profiles)user:1234 → {name, email, plan}
ListQueues, timelines, recent activitynotifications:user1 → [msg3, msg2, msg1]
SetUnique members (tags, friends)post:123:tags → {azure, cloud, devops}
Sorted SetLeaderboards, rankings (score-ordered)leaderboard → {alice:950, bob:900, eve:880}
StreamEvent logs, activity streamsOrdered event journal with consumer groups

Caching Patterns

Cache-Aside (Lazy Loading) — Most Common

  1. Application requests data
  2. Check Redis — if found (cache hit), return it
  3. If not found (cache miss), query the database
  4. Store result in Redis with TTL
  5. Return data to application

Write-Through

On every database write, also write to Redis. Keeps cache always up-to-date — no stale data — but higher write latency and may cache data that's rarely read.

Read-Through

Cache sits in front of the database. All reads go through cache — if miss, cache fetches from DB and populates itself. Application only talks to the cache.

💡
Always Set a TTL Always set an expiration (TTL) on cached keys — stale data that never expires can cause subtle bugs. Typical TTLs: product catalogue: 1 hour, user profile: 15 minutes, session: 30 minutes, frequently changing data: 1–5 minutes.

Session State Management

Redis is the standard solution for distributed session state in web applications. Instead of storing sessions on individual web servers (which breaks when you scale to multiple servers), store all sessions in Redis:

  • Any web server can serve any user — fully stateless web tier
  • Sessions survive web server restarts
  • Built-in TTL for automatic session expiry
  • Sub-millisecond session reads on every request

Pub/Sub Messaging

Redis pub/sub allows applications to publish messages to channels and subscribe to channels for real-time notifications. Use cases: real-time chat, live notifications, cache invalidation signals, event broadcasting.

Redis CLIBasic Redis commands
# Set with TTL (expire in 3600 seconds / 1 hour)
SET user:1234:profile "{name: 'Priya'}" EX 3600

# Get
GET user:1234:profile

# Increment counter atomically
INCR page:views:homepage

# Add to sorted set (leaderboard)
ZADD leaderboard 950 "alice"
ZADD leaderboard 900 "bob"

# Get top 3 (highest scores)
ZREVRANGE leaderboard 0 2 WITHSCORES

Persistence Options

By default, Redis is in-memory only — data is lost on restart. Premium and Enterprise tiers support persistence:

  • RDB (Redis Database) — Point-in-time snapshots at configurable intervals
  • AOF (Append Only File) — Log every write operation — can replay to reconstruct data

Geo-Replication

Premium tier supports passive geo-replication (one primary, one secondary). Enterprise tier supports active geo-replication — write to any region, all regions stay in sync. Use for global applications needing low-latency cache access from multiple regions.

💡
AZ-104 Exam Tip Know Basic tier has no SLA and no HA — dev/test only. Know Premium adds clustering, VNet, and persistence. Know Redis is for caching and session state — not primary database storage. Know cache-aside is the most common caching pattern.
📝 Practice Questions
Click an option to check your answer.
Q1. What is the primary benefit of Azure Cache for Redis compared to a relational database?
A — It provides much larger storage capacity
B — Sub-millisecond response times due to in-memory storage
C — Stronger ACID transaction guarantees
D — Support for complex SQL queries with joins
Q2. Which Azure Cache for Redis tier should be used for production workloads requiring high availability?
A — Basic
B — Standard
C — Only Premium supports production workloads
D — Basic with backup enabled
Q3. What Redis data structure is best for implementing a real-time leaderboard?
A — String
B — Hash
C — Sorted Set
D — Set
Q4. In the cache-aside pattern, what happens on a cache miss?
A — An error is returned to the application
B — The application queries the database, stores the result in Redis with a TTL, and returns the data
C — Redis automatically fetches the data from the database
D — Null is returned and the application handles it
Q5. Why is Redis ideal for storing web session state?
A — It is the cheapest storage option for session data
B — Shared access across all web servers, sub-millisecond reads, and built-in TTL for automatic expiry
C — It provides stronger encryption for sensitive session data
D — It can store unlimited session data without size constraints
Comments
Disclaimer: RedKite Cloud is an independent educational resource and is not affiliated with Microsoft Corporation.