![]() |
VOOZH | about |
dotnet add package StackExchange.Redis.Extensions.MsgPack --version 12.2.0
NuGet\Install-Package StackExchange.Redis.Extensions.MsgPack -Version 12.2.0
<PackageReference Include="StackExchange.Redis.Extensions.MsgPack" Version="12.2.0" />
<PackageVersion Include="StackExchange.Redis.Extensions.MsgPack" Version="12.2.0" />Directory.Packages.props
<PackageReference Include="StackExchange.Redis.Extensions.MsgPack" />Project file
paket add StackExchange.Redis.Extensions.MsgPack --version 12.2.0
#r "nuget: StackExchange.Redis.Extensions.MsgPack, 12.2.0"
#:package StackExchange.Redis.Extensions.MsgPack@12.2.0
#addin nuget:?package=StackExchange.Redis.Extensions.MsgPack&version=12.2.0Install as a Cake Addin
#tool nuget:?package=StackExchange.Redis.Extensions.MsgPack&version=12.2.0Install as a Cake Tool
StackExchange.Redis.Extensions is a library that extends StackExchange.Redis, making it easier to work with Redis in .NET applications. It wraps the base library with serialization, connection pooling, and higher-level APIs so you can store and retrieve complex objects without writing boilerplate code.
π CI
π CodeQL
π NuGet
π Tests
π .NET
AI-Ready: This library provides an file for AI coding assistants and a Claude Code plugin for configuration, scaffolding, and troubleshooting.
claude plugin add imperugo/StackExchange.Redis.ExtensionsThen use
/redis-configure,/redis-scaffold, or/redis-diagnosein Claude Code.
graph TB
App[Your Application] --> DI[ASP.NET Core DI]
DI --> Factory[IRedisClientFactory]
Factory --> Client1[IRedisClient - Default]
Factory --> Client2[IRedisClient - Named]
Client1 --> DB[IRedisDatabase]
DB --> Pool[Connection Pool Manager]
Pool --> C1[Connection 1]
Pool --> C2[Connection 2]
Pool --> C3[Connection N...]
DB --> Ser[ISerializer]
Ser --> Comp[CompressedSerializer?]
Comp --> Inner[System.Text.Json / Newtonsoft / ...]
C1 --> Redis[(Redis Server)]
C2 --> Redis
C3 --> Redis
dotnet add package StackExchange.Redis.Extensions.Core
dotnet add package StackExchange.Redis.Extensions.System.Text.Json
dotnet add package StackExchange.Redis.Extensions.AspNetCore
appsettings.json{
"Redis": {
"Password": "",
"AllowAdmin": true,
"Ssl": false,
"ConnectTimeout": 5000,
"SyncTimeout": 5000,
"Database": 0,
"Hosts": [
{ "Host": "localhost", "Port": 6379 }
],
"PoolSize": 5,
"IsDefault": true
}
}
var redisConfig = builder.Configuration.GetSection("Redis").Get<RedisConfiguration>();
builder.Services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(redisConfig);
public class MyService(IRedisDatabase redis)
{
public async Task Example()
{
// Store an object
await redis.AddAsync("user:1", new User { Name = "Ugo", Age = 38 });
// Retrieve it
var user = await redis.GetAsync<User>("user:1");
// Store with expiry
await redis.AddAsync("session:abc", sessionData, TimeSpan.FromMinutes(30));
// Bulk operations
var items = new[]
{
Tuple.Create("key1", "value1"),
Tuple.Create("key2", "value2"),
};
await redis.AddAllAsync(items, TimeSpan.FromHours(1));
// Search keys
var keys = await redis.SearchKeysAsync("user:*");
}
}
| Package | Description | NuGet |
|---|---|---|
| Core | Core library with abstractions and implementations | π NuGet |
| AspNetCore | ASP.NET Core DI integration and middleware | π NuGet |
| Package | Description | NuGet |
|---|---|---|
| System.Text.Json | Recommended for most scenarios | π NuGet |
| Newtonsoft | JSON.NET for legacy compatibility | π NuGet |
| MemoryPack | High-performance binary (net7.0+) | π NuGet |
| MsgPack | MessagePack binary format | π NuGet |
| Protobuf | Protocol Buffers | π NuGet |
| Utf8Json | UTF-8 native JSON | π NuGet |
| Package | Algorithm | Best for | NuGet |
|---|---|---|---|
| Compression.LZ4 | LZ4 | Lowest latency | π NuGet |
| Compression.Snappier | Snappy | Low latency | π NuGet |
| Compression.ZstdSharp | Zstandard | Best ratio/speed | π NuGet |
| Compression.GZip | GZip | Wide compatibility | π NuGet |
| Compression.Brotli | Brotli | Best ratio for text | π NuGet |
// Set a hash field
await redis.HashSetAsync("user:1", "name", "Ugo");
await redis.HashSetAsync("user:1", "email", "ugo@example.com");
// Get a hash field
var name = await redis.HashGetAsync<string>("user:1", "name");
// Set with per-field expiry (Redis 7.4+)
await redis.HashSetWithExpiryAsync("user:1", "session", sessionData, TimeSpan.FromMinutes(30));
// Query field TTL
var ttl = await redis.HashFieldGetTimeToLiveAsync("user:1", new[] { "session" });
// Add locations
await redis.GeoAddAsync("restaurants", new[]
{
new GeoEntry(13.361389, 38.115556, "Pizzeria Da Michele"),
new GeoEntry(15.087269, 37.502669, "Trattoria del Corso"),
new GeoEntry(12.496366, 41.902782, "Da Enzo al 29"),
});
// Distance between two places
var km = await redis.GeoDistanceAsync("restaurants",
"Pizzeria Da Michele", "Trattoria del Corso", GeoUnit.Kilometers);
// Search within 200km of a point
var nearby = await redis.GeoSearchAsync("restaurants", 13.361389, 38.115556,
new GeoSearchCircle(200, GeoUnit.Kilometers),
count: 10, order: Order.Ascending);
// Publish typed events
await redis.StreamAddAsync("orders", "payload", new Order { Id = 1, Total = 99.99m });
// Consumer group workflow
await redis.StreamCreateConsumerGroupAsync("orders", "processors");
var entries = await redis.StreamReadGroupAsync("orders", "processors", "worker-1");
foreach (var entry in entries)
{
// Process the message
await redis.StreamAcknowledgeAsync("orders", "processors", entry.Id!);
}
// Subscribe to typed messages
await redis.SubscribeAsync<OrderEvent>("orders:new", async order =>
{
Console.WriteLine($"New order: {order.Id}");
});
// Publish
await redis.PublishAsync("orders:new", new OrderEvent { Id = 42 });
// Enable transparent compression with any serializer
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(config);
services.AddRedisCompression<LZ4Compressor>(); // That's it!
// All operations automatically compress/decompress
await redis.AddAsync("large-data", myLargeObject); // stored compressed
var obj = await redis.GetAsync<MyObject>("large-data"); // decompressed automatically
var config = new RedisConfiguration { /* ... */ };
config.ConfigurationOptionsAsyncHandler = async opts =>
{
await opts.ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential());
return opts;
};
graph LR
subgraph Pool["Connection Pool (PoolSize=5)"]
C1["Connection 1<br/>Outstanding: 3"]
C2["Connection 2<br/>Outstanding: 0"]
C3["Connection 3<br/>Outstanding: 7"]
C4["Connection 4<br/>Outstanding: 1"]
C5["Connection 5<br/>Outstanding: 2"]
end
Op["GetConnection()"] -->|LeastLoaded| C2
Op -->|RoundRobin| C4
style C2 fill:#90EE90
style C4 fill:#87CEEB
The pool automatically skips disconnected connections and falls back gracefully when all connections are down, letting StackExchange.Redis's internal reconnection logic recover.
| Strategy | Behavior |
|---|---|
LeastLoaded (default) |
Picks the connected connection with fewest outstanding commands |
RoundRobin |
Random selection among connected connections |
All values stored in Redis go through the configured ISerializer. This means:
string value "hello" is stored as "\"hello\"" (JSON-encoded)IRedisDatabase.Database for raw Redis operations without serializationnull input produces an empty byte array| Property | Default | Description |
|---|---|---|
Hosts |
Required | Redis server endpoints |
Password |
null |
Redis password |
Database |
0 |
Database index |
Ssl |
false |
Enable TLS |
PoolSize |
5 |
Number of connections in the pool |
ConnectionSelectionStrategy |
LeastLoaded |
Pool selection strategy |
SyncTimeout |
5000 |
Sync operation timeout (ms) |
ConnectTimeout |
5000 |
Connection timeout (ms) |
KeyPrefix |
"" |
Prefix for all keys and channels |
AllowAdmin |
false |
Enable admin commands |
ClientName |
null |
Connection client name |
KeepAlive |
-1 |
Heartbeat interval (seconds). -1 = SE.Redis default, 0 = disabled |
ServiceName |
null |
Sentinel service name |
MaxValueLength |
0 |
Max serialized value size (0 = unlimited) |
WorkCount |
CPU*2 |
I/O threads per SocketManager |
ConnectRetry |
null |
Connection retry count |
CertificateValidation |
null |
TLS certificate validation callback |
CertificateSelection |
null |
TLS client certificate selection callback |
ConfigurationOptionsAsyncHandler |
null |
Async callback for custom ConfigurationOptions setup (e.g. Azure) |
Full documentation is available in the folder:
Getting Started
Configuration
Serializers
Features
Advanced
Thanks to all the people who already contributed!
<a href="https://github.com/imperugo/StackExchange.Redis.Extensions/graphs/contributors"> <img src="https://contributors-img.web.app/image?repo=imperugo/StackExchange.Redis.Extensions" /> </a>
Please read before submitting a pull request. PRs target the master branch only.
StackExchange.Redis.Extensions is Copyright Β© Ugo Lattanzi and other contributors under the .
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on StackExchange.Redis.Extensions.MsgPack:
| Package | Downloads |
|---|---|
|
Xinghe.Utility
XHεΊη‘εΊ(ε ι¨δ½Ώη¨) |
|
|
Traderr.Services
Traderr.io |
|
|
VRSPRO.Common.Cache
A set of internal generic classes and extensions for working with caches, databases, queues, message brokers, files, reflection, errors, , pagination, collections, strings, and ASP NET CORE. You can use this code in your projects as is. You can copy, modify and distribute it without any restrictions. You do not need to provide any copyrights or references. |
|
|
Pandatech.DistributedCache
Lightweight distributed caching library for .NET 9+ implementing Microsoft's HybridCache abstraction on top of Redis. Provides strongly typed caching with MessagePack serialization, distributed locking, rate limiting, stampede protection, and tag-based invalidation. Less than 500 lines of code for easy understanding and maintenance. Built on StackExchange.Redis with automatic health checks. |
|
|
JC.NetCore.Cache
JC.NetCore.Cache is a library that extends StackExchange.Redis and Faster allowing you a set of functionality needed by common applications. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 12.2.0 | 1,642 | 5/22/2026 |
| 12.1.0 | 2,540 | 4/11/2026 |
| 12.0.0 | 148 | 4/11/2026 |
| 11.0.0 | 228,244 | 1/20/2025 |
| 10.2.0 | 249,523 | 1/23/2024 |
| 10.1.0 | 45,772 | 1/7/2024 |
| 10.0.2 | 1,311 | 12/25/2023 |
| 10.0.1 | 487 | 12/23/2023 |
| 10.0.0 | 432 | 12/23/2023 |
| 9.1.0 | 145,632 | 3/1/2023 |
| 9.0.0 | 2,377 | 2/20/2023 |
| 8.0.5 | 219,067 | 5/24/2022 |
| 8.0.4 | 32,751 | 2/14/2022 |
| 8.0.3 | 19,199 | 1/14/2022 |
| 8.0.2 | 1,333 | 1/8/2022 |
| 8.0.1 | 737 | 1/7/2022 |
| 8.0.0 | 755 | 1/7/2022 |
| 7.2.1 | 91,837 | 11/19/2021 |
| 7.1.1 | 140,230 | 6/25/2021 |
| 7.0.1 | 12,366 | 5/21/2021 |
v12.2.0:
- Fixed SearchKeysAsync ignoring database number β SCAN now correctly targets the specified database instead of always scanning DB0 (#651)
- Fixed RemoveByTagAsync not deleting the tag Set key itself, causing a slow memory leak of empty tag Sets in Redis (#650)
v12.1.0:
- Added VectorSet API for AI/ML similarity search (Redis 8.0+): VADD, VSIM, VREM, VCONTAINS, VCARD, VDIM, VGETATTR, VSETATTR, VINFO, VRANDMEMBER, VLINKS
- Added llms.txt for AI coding assistant documentation indexing
- Added Claude Code plugin with configure, scaffold, and diagnose skills
- Added complete API reference tables to all feature documentation
- Added SECURITY.md with GitHub Private Vulnerability Reporting
- Added CodeQL Advanced security analysis workflow
- Added CI workflow for automated testing on push/PR
v12.0.0:
- Added .NET 10 target framework
- Added GeoSpatial API (GEOADD, GEOSEARCH, GEODIST, GEOPOS, GEOHASH)
- Added Redis Streams API (XADD, XREAD, XREADGROUP, XACK, consumer groups)
- Added Hash field expiry (HEXPIRE, HSETEX, HPTTL, HPERSIST) for Redis 7.4+
- Added transparent compression support with pluggable ICompressor
- Added compression packages: LZ4, Snappy, Zstandard, GZip, Brotli
- Added Azure Managed Identity support via ConfigurationOptionsAsyncHandler
- Added CertificateSelection, ClientName, KeepAlive configuration properties
- Fixed SyncTimeout default from 1000ms to 5000ms
- Fixed Sentinel CommandMap blocking data commands (EVAL, GET, SET)
- Fixed AddAllAsync TTL race condition (now atomic per key)
- Fixed pool resilience: GetConnection skips disconnected connections
- Fixed PubSub handler silently swallowing exceptions
- Upgraded to StackExchange.Redis 2.12.14
- Upgraded to ConnectAsync (SE.Redis best practice)
- Replaced Moq with NSubstitute