Quick start
Two minutes, one file. You need the .NET 10 SDK and a
Redis-compatible server. Respire runs on .NET 8 and .NET 10. To target .NET 8, keep
net8.0 and build with the .NET 10 SDK, or set <LangVersion>13</LangVersion> or later.
1. Start Redis
If you don't have a server running, start one with Docker:
docker run --name respire-redis --rm -d -p 6379:6379 redis:8
Valkey, KeyDB, and managed services such as Azure Managed Redis, Amazon ElastiCache, and Google Cloud Memorystore work too. Pass their connection string in step 3.
2. Create an app
dotnet new console -n HelloRespire
cd HelloRespire
dotnet add package Respire
3. Write some Redis code
Replace Program.cs with:
using Respire;
await using var redis = await RespireClient.ConnectAsync("redis://localhost");
// Strings, with an expiry
await redis.SetAsync("greeting", "Hello from Respire", expiry: TimeSpan.FromMinutes(5));
Console.WriteLine(await redis.GetStringAsync("greeting"));
// Your own types, serialized as JSON
await redis.SetAsync("player:ada", new Player("Ada", Level: 7));
Player? ada = await redis.GetAsync<Player>("player:ada");
Console.WriteLine($"{ada?.Name} is level {ada?.Level}");
// Counters
long visits = await redis.IncrementAsync("visits");
Console.WriteLine($"Visit number {visits}");
// Other data types live behind facets: Hashes, Lists, Sets, SortedSets, Streams...
await redis.SortedSets.AddAsync("leaderboard", ("ada", 98.5), ("grace", 97.5));
string[] top = await redis.SortedSets.RangeAsync("leaderboard", 0, 2, descending: true);
Console.WriteLine($"Leader: {top[0]}");
record Player(string Name, int Level);
4. Run it
dotnet run
Hello from Respire
Ada is level 7
Visit number 1
Leader: ada
That's it: no multiplexer, no RedisValue, no configuration. The client pipelines
concurrent calls automatically and reconnects if the connection drops. Create one client
when your app starts and share it everywhere.
ConnectAsync accepts Redis URIs (rediss://user:password@host:6380 for TLS), connection
strings copied from the Azure portal, and StackExchange.Redis connection strings. Add
?cluster=true for Redis Cluster or ?serviceName=mymaster for Sentinel. See
Connections.
Next steps
- Build an ASP.NET Core app. Dependency injection, typed endpoints, pub/sub, and batches.
- Make hot reads local. Turn on client-side caching and cache-aside with one option.
- Recipes. Leaderboards, sessions, an outbox, and leader election.
- Distributed locks and job queues.
- Test without Docker. Use the in-memory server.