Skip to main content

Redis Provider

The Redis provider offers key-value storage with TTL support, pub/sub integration, and dedicated inbox/outbox store implementations for the messaging infrastructure.

Before You Start

  • .NET 10.0
  • A Redis instance (local, Azure Cache for Redis, or ElastiCache)
  • Familiarity with data access and caching

Installation

dotnet add package Excalibur.Data.Redis

Dependencies: Excalibur.Data.Abstractions, StackExchange.Redis

Quick Start

using Microsoft.Extensions.DependencyInjection;

// Inbox with Redis
services.AddExcaliburInbox(inbox =>
{
inbox.UseRedis(redis =>
{
redis.ConnectionString("localhost:6379")
.KeyPrefix("inbox")
.Database(0);
});
});

Registration

All Redis subsystem builders support 4 canonical connection overloads: ConnectionString(), Multiplexer(), MultiplexerFactory(), and BindConfiguration().

Inbox Store

services.AddExcaliburInbox(inbox =>
{
inbox.UseRedis(redis =>
{
redis.ConnectionString("localhost:6379")
.KeyPrefix("myapp-inbox")
.Database(0);
});
});

Outbox Store

services.AddExcalibur(excalibur => excalibur.AddOutbox(outbox =>
{
outbox.UseRedis(redis =>
{
redis.ConnectionString("localhost:6379")
.KeyPrefix("outbox")
.Database(1);
});
}));

Event Sourcing

services.AddExcalibur(excalibur => excalibur.AddEventSourcing(es =>
{
es.UseRedis(redis =>
{
redis.ConnectionString("localhost:6379")
.KeyPrefix("myapp")
.Database(0);
})
.AddRepository<OrderAggregate, Guid>();
}));

Leader Election

services.AddExcalibur(excalibur => excalibur.AddLeaderElection(le =>
{
le.UseRedis(redis =>
{
redis.ConnectionString("localhost:6379")
.LockKey("myapp:leader")
.Database(0);
});
}));

Use Cases

Redis is primarily used in Excalibur for:

  • Inbox deduplication — Ensure messages are processed exactly once
  • Outbox store — Reliable message publishing with at-least-once delivery
  • Caching layer — Paired with Excalibur.Dispatch.Caching for middleware-level caching
  • Leader election — See Excalibur.LeaderElection.Redis

See Also