Azure Redis Cache libraries for .NET

Overview

Azure Redis Cache 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 Redis Cache.

Client library

Azure Redis Cache 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 Redis Cache 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 Redis Cache management library allows you to manage Redis Cache 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 Redis Cache.

/* 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