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>();
}));

The event store writes each event's declared [MessageName] -- not its CLR type name -- to the stored event-type field, and resolves that name back to a CLR type through the registered event-type registry on read. See Stable Message Names.

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 — Turn at-least-once delivery into effectively-once processing per (MessageId, HandlerType). Exactly-once for concurrent redelivery; at-least-once across a process crash, because the claim and the post-handler mark are two steps rather than one transaction — so handlers must be idempotent
  • 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​