Redis Configure
Developmentredis-configureRedis Configure is an Agent Skill for development published in the imperugo/StackExchange.Redis.Extensions repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Generate StackExchange.Redis.Extensions configuration and DI registration from natural language requirements
QUICK START
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/imperugo/StackExchange.Redis.Extensions/blob/HEAD/claude-plugin/skills/configure/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/redis-configure, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Redis Configure
Generate complete RedisConfiguration and ASP.NET Core DI setup for StackExchange.Redis.Extensions based on the user's requirements.
When to use
When the user asks to:
- Set up Redis in their .NET project
- Configure connection pooling, Sentinel, TLS, Azure Managed Identity
- Choose a serializer or compressor
- Set up multiple Redis instances
How to respond
- Ask clarifying questions if needed (single vs. multi-instance, cloud vs. local, auth method)
- Generate the complete configuration
Configuration Reference
NuGet packages required
StackExchange.Redis.Extensions.Core— always requiredStackExchange.Redis.Extensions.AspNetCore— for DI registration- One serializer:
System.Text.Json(recommended),Newtonsoft,MemoryPack,MsgPack,Protobuf,ServiceStack,Utf8Json - Optional compressor:
Compression.LZ4(fastest),Compression.Snappier,Compression.ZstdSharp(best ratio),Compression.GZip(no deps),Compression.Brotli(best ratio for text)
appsettings.json structure
{
"Redis": {
"Password": "",
"AllowAdmin": true,
"Ssl": false,
"ConnectTimeout": 5000,
"SyncTimeout": 5000,
"Database": 0,
"Hosts": [{ "Host": "localhost", "Port": 6379 }],
"PoolSize": 5,
"IsDefault": true
}
}
Program.cs registration
var redisConfig = builder.Configuration.GetSection("Redis").Get<RedisConfiguration>();
builder.Services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(redisConfig);
// Optional compression:
builder.Services.AddRedisCompression<LZ4Compressor>();
Azure Managed Identity
redisConfig.ConfigurationOptionsAsyncHandler = async opts =>
{
await opts.ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential());
return opts;
};
Sentinel configuration
var config = new RedisConfiguration
{
ServiceName = "mymaster",
Hosts = new[] {
new RedisHost { Host = "sentinel1", Port = 26379 },
new RedisHost { Host = "sentinel2", Port = 26379 },
},
IsDefault = true,
};
Multiple instances with Keyed DI (.NET 8+)
var configs = new[]
{
new RedisConfiguration { Name = "Cache", IsDefault = true, /* ... */ },
new RedisConfiguration { Name = "Session", /* ... */ },
};
builder.Services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(configs);
// Option 1: Keyed DI Services (.NET 8+)
public class MyService(
[FromKeyedServices("Cache")] IRedisDatabase cacheDb,
[FromKeyedServices("Session")] IRedisDatabase sessionDb) { }
// Option 2: Factory pattern (all TFMs)
// inject IRedisClientFactory, call GetRedisClient("Session")
Health Check
builder.Services.AddHealthChecks()
.AddRedisExtensionsHealthCheck(
name: "redis",
tags: new[] { "db", "cache", "ready" });
IDistributedCache adapter
// Call after AddStackExchangeRedisExtensions
builder.Services.AddRedisDistributedCache();
// Uses Hash-based storage compatible with Microsoft.Extensions.Caching.StackExchangeRedis
// Supports sliding expiration, absolute expiration, and refresh
Key properties
| 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) |
Serializer selection guide
| Scenario | Recommended |
|---|---|
| General purpose | System.Text.Json |
| Legacy JSON.NET compatibility | Newtonsoft |
| Maximum performance (binary) | MemoryPack (net8.0+) |
| Cross-language compatibility | Protobuf or MsgPack |
Compressor selection guide
| Scenario | Recommended |
|---|---|
| Lowest latency (caching) | LZ4 |
| Best compression ratio | ZstdSharp or Brotli |
| No external dependencies | GZip |