Skip to content

Commit b46e3d7

Browse files
committed
updated file
1 parent 01f349b commit b46e3d7

1 file changed

Lines changed: 36 additions & 37 deletions

File tree

articles/redis/dotnet.md

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
## Microsoft.Azure.StackExchangeRedis Sample Application
1+
---
2+
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.
216

3-
### Overview
17+
## Skip to the code on GitHub
418

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.
620

7-
### Required NuGet Packages
21+
## Required NuGet Packages
822

923
| Package | Purpose |
10-
|---------|---------|
24+
|||
1125
| `Microsoft.Azure.StackExchangeRedis` | Extension library that adds Entra ID authentication to StackExchange.Redis |
1226
| `Azure.Identity` | Provides `DefaultAzureCredential` and other Azure identity implementations |
1327
| `StackExchange.Redis` | The underlying Redis client (pulled in as a dependency) |
1428
| `Microsoft.Extensions.Logging.Console` | Console logging for diagnostics |
1529

16-
---
17-
18-
### Authentication Methods
30+
## Authentication Methods
1931

2032
The extension supports multiple identity types, each with a corresponding `ConfigureForAzure*()` extension method:
2133

@@ -29,8 +41,6 @@ The extension supports multiple identity types, each with a corresponding `Confi
2941

3042
5. **Service Principal (Certificate)** — Client ID + Tenant ID + X.509 certificate for higher security.
3143

32-
---
33-
3444
### How `DefaultAzureCredential` Works Locally
3545

3646
When developing locally, `DefaultAzureCredential` will attempt to authenticate using:
@@ -41,9 +51,7 @@ az login
4151

4252
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.
4353

44-
---
45-
46-
### Key Implementation Patterns
54+
## Key Implementation Patterns
4755

4856
**Connection Configuration:**
4957

@@ -72,9 +80,7 @@ await database.StringSetAsync("key", "value");
7280
var value = await database.StringGetAsync("key");
7381
```
7482

75-
---
76-
77-
### Token Lifecycle & Automatic Re-authentication
83+
## Token Lifecycle & Automatic Re-authentication
7884

7985
The extension handles the OAuth2 token lifecycle automatically:
8086

@@ -85,15 +91,13 @@ The extension handles the OAuth2 token lifecycle automatically:
8591
You can subscribe to token events for observability:
8692

8793
| Event | Purpose |
88-
|-------|---------|
94+
|-||
8995
| `TokenRefreshed` | New token acquired |
9096
| `TokenRefreshFailed` | Token refresh failed (still using old token) |
9197
| `ConnectionReauthenticated` | Connection successfully re-authenticated |
9298
| `ConnectionReauthenticationFailed` | Re-auth failed for a connection |
9399

94-
---
95-
96-
### RESP3 vs RESP2 Protocol
100+
## RESP3 vs RESP2 Protocol
97101

98102
The sample uses **RESP3** (`Protocol = RedisProtocol.Resp3`) because:
99103

@@ -102,48 +106,43 @@ The sample uses **RESP3** (`Protocol = RedisProtocol.Resp3`) because:
102106
- Pub/sub connections close when their token expires, causing brief interruptions.
103107
- RESP3 multiplexes everything on one connection, avoiding these disruptions.
104108

105-
---
106-
107-
### Azure Prerequisites
109+
## Azure Prerequisites
108110

109111
1. **Create an Azure Managed Redis** instance.
110112
2. **Enable Microsoft Entra ID authentication** under "Data Access Configuration."
111113
3. **Add your identity as a Redis User** with the appropriate permissions (Data Owner, Data Contributor, etc.).
112114
4. **Run `az login`** locally to authenticate with your Entra ID account.
113115

114-
---
115-
116-
### Redis Basics Refresher
116+
## Redis Basics Refresher
117117

118118
| Concept | Description |
119-
|---------|-------------|
119+
||-|
120120
| `ConnectionMultiplexer` | Singleton, thread-safe connection pool to Redis—create once, reuse for the app lifetime. |
121121
| `IDatabase` | Interface for executing commands (`StringGet`, `StringSet`, `HashGet`, etc.). |
122122
| Endpoint format | `endpoint:10000` (TLS) for Azure Managed Redis. |
123123
| Commands | Redis is single-threaded per key—atomic operations like `INCR`, `SETNX` avoid race conditions. |
124124

125-
---
126-
127-
### Running the Sample
125+
## Running the Sample
128126

129127
```powershell
130128
az login
131129
cd sample
132130
dotnet run
133131
```
134132

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.
136134

137-
---
138-
139-
### Production Considerations
135+
## Production Considerations
140136

141137
| Setting | Sample Value | Production Value |
142-
|---------|--------------|------------------|
138+
||--||
143139
| `AbortOnConnectFail` | `true` | `false` (retry on startup) |
144140
| `BacklogPolicy` | `FailFast` | `Default` (queue commands during transient failures) |
145141
| Connection lifetime | Demo loop | Singleton via DI (`IConnectionMultiplexer`) |
146142

147-
---
148-
149143
This sample provides a complete reference implementation for secure, passwordless Entra ID authentication in any .NET application that uses Azure Managed Redis.
144+
145+
## Related content
146+
147+
- [Connection resilience](best-practices-connection.md)
148+
- [Best Practices Development](best-practices-development.md)

0 commit comments

Comments
 (0)