OpenParable
Skip to content
← Back to skills

Redis Configure

Development
redis-configure

Redis 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

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. 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

  1. Ask clarifying questions if needed (single vs. multi-instance, cloud vs. local, auth method)
  2. Generate the complete configuration

Configuration Reference

NuGet packages required

  • StackExchange.Redis.Extensions.Core — always required
  • StackExchange.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

PropertyDefaultDescription
PoolSize5Connection pool size
ConnectionSelectionStrategyLeastLoadedLeastLoaded or RoundRobin
SyncTimeout5000Sync timeout (ms)
ConnectTimeout5000Connect timeout (ms)
KeyPrefix""Prefix for all keys and channels
KeepAlive-1Heartbeat interval (seconds)
ClientNamenullConnection client name
MaxValueLength0Max serialized value size (0 = unlimited)

Serializer selection guide

ScenarioRecommended
General purposeSystem.Text.Json
Legacy JSON.NET compatibilityNewtonsoft
Maximum performance (binary)MemoryPack (net8.0+)
Cross-language compatibilityProtobuf or MsgPack

Compressor selection guide

ScenarioRecommended
Lowest latency (caching)LZ4
Best compression ratioZstdSharp or Brotli
No external dependenciesGZip