Generate StackExchange.Redis.Extensions configuration and DI registration from natural language requirements
Generate complete RedisConfiguration and ASP.NET Core DI setup for StackExchange.Redis.Extensions based on the user's requirements.
When the user asks to:
StackExchange.Redis.Extensions.Core — always requiredStackExchange.Redis.Extensions.AspNetCore — for DI registrationSystem.Text.Json (recommended), , , , , , NewtonsoftMemoryPackMsgPackProtobufServiceStackUtf8JsonCompression.LZ4 (fastest), Compression.Snappier, Compression.ZstdSharp (best ratio), Compression.GZip (no deps), Compression.Brotli (best ratio for text){
"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);
// Optional compression:
builder.Services.AddRedisCompression<LZ4Compressor>();
redisConfig.ConfigurationOptionsAsyncHandler = async opts =>
{
await opts.ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential());
return opts;
};
var config = new RedisConfiguration
{
ServiceName = "mymaster",
Hosts = new[] {
new RedisHost { Host = "sentinel1", Port = 26379 },
new RedisHost { Host = "sentinel2", Port = 26379 },
},
IsDefault = true,
};
var configs = new[]
{
new RedisConfiguration { Name = "Cache", IsDefault = true, /* ... */ },
new RedisConfiguration { Name = "Session", /* ... */ },
};
builder.Services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(configs);
// Resolve: inject IRedisClientFactory, call GetRedisClient("Session")
| Property | Default | Description |
|---|---|---|
| PoolSize | 5 | Connection pool size |
| ConnectionSelectionStrategy | LeastLoaded | LeastLoaded or RoundRobin |
| SyncTimeout | 5000 | Sync timeout (ms) |
| ConnectTimeout | 5000 | Connect timeout (ms) |
| KeyPrefix | "" | Prefix for all keys and channels |
| KeepAlive | -1 | Heartbeat interval (seconds) |
| ClientName | null | Connection client name |
| MaxValueLength | 0 | Max serialized value size (0 = unlimited) |
| Scenario | Recommended |
|---|---|
| General purpose | System.Text.Json |
| Legacy JSON.NET compatibility | Newtonsoft |
| Maximum performance (binary) | MemoryPack (net8.0+) |
| Cross-language compatibility | Protobuf or MsgPack |
| Scenario | Recommended |
|---|---|
| Lowest latency (caching) | LZ4 |
| Best compression ratio | ZstdSharp or Brotli |
| No external dependencies | GZip |