page_type | languages | name | description | products | ||||
---|---|---|---|---|---|---|---|---|
sample |
|
Quickstart: Use Azure Cache for Redis in .NET Core |
Learn how to incorporate Azure Cache for Redis into a C# .NET Core console app using the StackExchange.Redis Redis client. |
|
See the accompanying article on the documentation site for details, including best practices and how to create the sample code from scratch.
- Azure subscription - create one for free
- Azure Cache for Redis cache - create one
- .NET Core SDK
- Azure Developer CLI
Download the sample code to your development PC.
This sample uses Microsoft Entra ID to authenticate connections to an Azure Cache for Redis resource.
The following line of code in RedisConnection.cs
obtains the default credential from your local machine or an Azure resource as the identity for authentication and authorization.
var configurationOptions = await ConfigurationOptions.Parse($"{_redisHostName}:6380").ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential());
One of the common way for signing into to your Azure account is to use the Azure developer CLI. Bring up the Command Prompt. Run
azd auth login
For more information on signing into Azure with Azure developer CLI, see azd auth login
Follow instruction at Use Microsoft Entra ID for cache authentication
dotnet restore
{
"RedisHostName": "<your_redis_name>.redis.cache.windows.net"
}
dotnet build
Then run the app with the following command:
dotnet run