Genocs.Saga.Integrations.Redis Agent Reference

This document is optimized for AI-assisted development sessions.

Genocs.Saga.Integrations.Redis Agent Reference

Purpose

This document is optimized for AI-assisted development sessions. It prioritizes fast retrieval of:

  • What Genocs.Saga.Integrations.Redis is responsible for
  • Which APIs to call for specific goals
  • Where source of truth lives
  • What constraints and runtime behaviors matter

Quick Facts

KeyValue
PackageGenocs.Saga.Integrations.Redis
Project filesrc/Genocs.Saga.Integrations.Redis/Genocs.Saga.Integrations.Redis.csproj
Target frameworksnet10.0, net9.0, net8.0
Primary roleRedis-backed saga state and log persistence integration for Genocs.Saga
Core themesUseRedisPersistence extensions, StackExchangeRedis cache registration, JSON serialization of saga state/log, Redis key-based persistence

Use This Package When

  • Persisting saga state and saga log entries to Redis.
  • Sharing saga persistence across service instances with a distributed cache backend.
  • Registering saga persistence with StackExchange Redis cache options.
  • Running compensation flows that depend on persisted saga log history.
  • Using explicit SagaRedisSettings in startup wiring.

Do Not Assume

  • UseRedisPersistence with IConfiguration expects the section value to be JSON text, not a standard object-bound section.
  • Redis persistence uses key patterns based on id and type hash code, not typed collections.
  • Write paths assume non-null message and state data values when calling GetType.

High-Value Entry Points

Integration registration

Configuration model

Redis persistence implementations

Core saga contracts consumed

Decision Matrix For Agents

GoalPreferred APINotes
Enable Redis persistence from explicit settingsUseRedisPersistence(builder, SagaRedisSettings)Most direct and predictable registration path
Enable Redis persistence from configurationUseRedisPersistence(builder, sectionName, IConfiguration)Expects JSON string in section value and deserializes with Newtonsoft.Json
Persist saga state snapshotISagaStateRepository.WriteAsync via RedisSagaStateRepositoryStores serialized RedisSagaState under generated state key
Reload saga state for next messageISagaStateRepository.ReadAsync via RedisSagaStateRepositoryDeserializes state and rehydrates Data from JObject with DataType
Persist saga log historyISagaLog.WriteAsync via RedisSagaLogReads current list, appends new log item, writes back serialized list
Load compensation log historyISagaLog.ReadAsync via RedisSagaLogReturns deserialized log entries for saga id and type
Delete saga state manuallyRedisSagaStateRepository.DeleteAsyncRemoves state key from distributed cache
Delete saga log manuallyRedisSagaLog.DeleteAsyncRemoves log key from distributed cache

Minimal Integration Recipe

Install

dotnet add package Genocs.Saga.Integrations.Redis

Setup in Program.cs

using Genocs.Saga;
using Genocs.Saga.Integrations.Redis;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSaga(saga =>
{
    saga.UseRedisPersistence(new SagaRedisSettings
    {
        Configuration = "localhost:6379",
        InstanceName = "genocs-saga"
    });
});

var app = builder.Build();

app.Run();

Behavior Notes That Affect Agent Decisions

  • Configuration overload deserializes from configuration section raw value; malformed or missing JSON triggers SagaException.
  • ConfigureRedisPersistence registers IDistributedCache via AddStackExchangeRedisCache.
  • State keys and log keys are computed using id plus type hash code suffix.
  • RedisSagaStateRepository rehydrates Data from JObject using stored DataType after deserialization.
  • Read and write methods validate required arguments and throw SagaException on null/whitespace inputs.
  • Log writes use read-modify-write of the full log list under one key.

Source-Accurate Capability Map

Builder integration and DI wiring

  • Extends ISagaBuilder to plug Redis persistence into saga runtime.
  • Supports settings from explicit object or configuration value deserialization.
  • Registers distributed cache and binds saga log/state contracts to Redis implementations.

Files:

Saga state persistence on distributed cache

  • Stores and retrieves serialized RedisSagaState payloads per saga key.
  • Rehydrates dynamic saga data payload to original runtime type when DataType is available.
  • Supports explicit state deletion.

Files:

Saga log persistence on distributed cache

  • Stores saga log entry list as serialized JSON in cache.
  • Rehydrates logged message payloads by stored message type.
  • Supports explicit log deletion.

Files:

Core saga contract interoperability

  • Integrates through ISagaBuilder extension points.
  • Implements ISagaStateRepository and ISagaLog interfaces expected by saga managers.

Files:

Dependencies

From src/Genocs.Saga.Integrations.Redis/Genocs.Saga.Integrations.Redis.csproj:

  • Genocs.Saga (project reference in Debug, package reference in Release)
  • Microsoft.Extensions.Caching.StackExchangeRedis
  • Newtonsoft.Json
  • Microsoft.Extensions.Configuration