You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "Quickstart: Use Azure Managed Redis in .NET Core"
3
+
description: In this quickstart, learn how to use Azure Managed Redis in a .NET console app
4
+
ms.date: 01/30/2026
5
+
ms.topic: quickstart
6
+
ms.devlang: csharp
7
+
zone_pivot_groups: redis-type
8
+
appliesto:
9
+
- ✅ Azure Managed Redis
10
+
# Customer intent: As a .NET developer, new to Azure Managed Redis, I want to create a new dotnet app that uses Azure Managed Redis.
11
+
---
12
+
13
+
# Quickstart: Use Azure Redis in .NET Core
14
+
15
+
This is a .NET 8 console application that demonstrates how to connect to **Azure Managed Redis** using **Microsoft Entra ID** authentication. The core value proposition is **passwordless authentication** with automatic token refresh, providing a secure and modern approach to Redis connectivity.
2
16
3
-
### Overview
17
+
##Skip to the code on GitHub
4
18
5
-
This is a .NET 8 console application that demonstrates how to connect to **Azure Managed Redis** using **Microsoft Entra ID** (formerly Azure Active Directory) authentication. The core value proposition is **passwordless authentication** with automatic token refresh, providing a secure and modern approach to Redis connectivity.
19
+
Clone the repo [Microsoft.Azure.StackExchangeRedis](https://github.com/Azure/Microsoft.Azure.StackExchangeRedis/tree/main/sample) on GitHub.
6
20
7
-
###Required NuGet Packages
21
+
## Required NuGet Packages
8
22
9
23
| Package | Purpose |
10
-
|---------|---------|
24
+
|||
11
25
|`Microsoft.Azure.StackExchangeRedis`| Extension library that adds Entra ID authentication to StackExchange.Redis |
12
26
|`Azure.Identity`| Provides `DefaultAzureCredential` and other Azure identity implementations |
13
27
|`StackExchange.Redis`| The underlying Redis client (pulled in as a dependency) |
14
28
|`Microsoft.Extensions.Logging.Console`| Console logging for diagnostics |
15
29
16
-
---
17
-
18
-
### Authentication Methods
30
+
## Authentication Methods
19
31
20
32
The extension supports multiple identity types, each with a corresponding `ConfigureForAzure*()` extension method:
21
33
@@ -29,8 +41,6 @@ The extension supports multiple identity types, each with a corresponding `Confi
29
41
30
42
5.**Service Principal (Certificate)** — Client ID + Tenant ID + X.509 certificate for higher security.
31
43
32
-
---
33
-
34
44
### How `DefaultAzureCredential` Works Locally
35
45
36
46
When developing locally, `DefaultAzureCredential` will attempt to authenticate using:
@@ -41,9 +51,7 @@ az login
41
51
42
52
This signs you into the Azure CLI with your Microsoft Entra ID account. The SDK detects your cached credentials and uses them to obtain tokens. Your Entra ID user must be configured as a **Redis User** on the Azure Managed Redis resource via the **Data Access Configuration** blade in the Azure portal.
- Pub/sub connections close when their token expires, causing brief interruptions.
103
107
- RESP3 multiplexes everything on one connection, avoiding these disruptions.
104
108
105
-
---
106
-
107
-
### Azure Prerequisites
109
+
## Azure Prerequisites
108
110
109
111
1.**Create an Azure Managed Redis** instance.
110
112
2.**Enable Microsoft Entra ID authentication** under "Data Access Configuration."
111
113
3.**Add your identity as a Redis User** with the appropriate permissions (Data Owner, Data Contributor, etc.).
112
114
4.**Run `az login`** locally to authenticate with your Entra ID account.
113
115
114
-
---
115
-
116
-
### Redis Basics Refresher
116
+
## Redis Basics Refresher
117
117
118
118
| Concept | Description |
119
-
|---------|-------------|
119
+
||-|
120
120
|`ConnectionMultiplexer`| Singleton, thread-safe connection pool to Redis—create once, reuse for the app lifetime. |
121
121
|`IDatabase`| Interface for executing commands (`StringGet`, `StringSet`, `HashGet`, etc.). |
122
122
| Endpoint format |`endpoint:10000` (TLS) for Azure Managed Redis. |
123
123
| Commands | Redis is single-threaded per key—atomic operations like `INCR`, `SETNX` avoid race conditions. |
124
124
125
-
---
126
-
127
-
### Running the Sample
125
+
## Running the Sample
128
126
129
127
```powershell
130
128
az login
131
129
cd sample
132
130
dotnet run
133
131
```
134
132
135
-
Enter your Redis endpoint (e.g., `myredis.redis.azure.net`), choose authentication method **1** (DefaultAzureCredential), and watch the `+` characters print every second as commands succeed. Let it run for 60+ minutes to verify automatic token refresh works.
133
+
Enter your Redis endpoint (e.g., <myredis.redis.azure.net:1000>), choose authentication method **1** (DefaultAzureCredential), and watch the `+` characters print every second as commands succeed. Let it run for 60+ minutes to verify automatic token refresh works.
136
134
137
-
---
138
-
139
-
### Production Considerations
135
+
## Production Considerations
140
136
141
137
| Setting | Sample Value | Production Value |
142
-
|---------|--------------|------------------|
138
+
||--||
143
139
|`AbortOnConnectFail`|`true`|`false` (retry on startup) |
144
140
|`BacklogPolicy`|`FailFast`|`Default` (queue commands during transient failures) |
145
141
| Connection lifetime | Demo loop | Singleton via DI (`IConnectionMultiplexer`) |
146
142
147
-
---
148
-
149
143
This sample provides a complete reference implementation for secure, passwordless Entra ID authentication in any .NET application that uses Azure Managed Redis.
0 commit comments