Azure Cache for Redis libraries for .NET

Overview

Azure Cache for Redis is a secure data cache and messaging broker that provides high throughput and low-latency access to data for applications. For more information, see How to Use Azure Cache for Redis.

Client library

Azure Cache for Redis is compatible with any Redis client API, including StackExchange.Redis.

Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio Package Manager

Install-Package StackExchange.Redis
dotnet add package StackExchange.Redis

Example

This example connects to a Azure Cache for Redis database instance, adds some strings to the cache by name, and then retrieves them again.

/* Include this "using" directive.
using StackExchange.Redis;
*/

ConnectionMultiplexer connection = 
    ConnectionMultiplexer.Connect("contoso.redis.cache.windows.net,abortConnect=false,ssl=true,password=...");
    IDatabase cache = connection.GetDatabase();

// Perform cache operations using the cache object...
// Simple put of integral data types into the cache
cache.StringSet("key1", "value");
cache.StringSet("key2", 25);

// Simple get of data types from the cache
string key1 = cache.StringGet("key1");
int key2 = (int)cache.StringGet("key2");

Management library

The Azure Cache for Redis management library allows you to manage Azure Cache for Redis resources and access keys.

Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio Package Manager

Install-Package Microsoft.Azure.Management.Redis.Fluent
dotnet add package Microsoft.Azure.Management.Redis.Fluent

Example

This example creates a new Azure Cache for Redis.

/* Include these "using" directives...
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Management.Redis.Fluent;
*/

IRedisCache redisCache1 = azure.RedisCaches.Define("RedisCacheName")
    .WithRegion(Region.USCentral)
    .WithNewResourceGroup("ResourceGroupName")
    .WithBasicSku()
    .Create();

Samples