ข้ามไปยังเนื้อหา

Class RedisEventStore

เนื้อหานี้ยังไม่ได้แปลเป็นภาษาไทย แสดงเป็นภาษาอังกฤษแทน

Namespace: Cephalon.EventSourcing.Redis
Assembly: Cephalon.EventSourcing.Redis.dll

Redis Streams-backed implementation of that appends domain events as stream entries.

public sealed class RedisEventStore : IEventStore

objectRedisEventStore

IEventStore

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Each logical event stream is stored as a Redis Stream at key {keyPrefix}stream:{streamId}. Every entry in the stream carries the fields StreamVersion, EventType, Payload, OccurredAtUtc, and AppendedAtUtc.

Concurrency semantics: this provider performs an optimistic check — it reads the current stream version before appending and throws if the version does not match. There is no atomic test-and-set; a narrow concurrent race between the version read and the subsequent XADD calls is possible. This is a known limitation of this slice. For workloads requiring stronger guarantees, consider pairing with a Lua script or Redis transactions (MULTI/EXEC) in a future slice.

RedisEventStore(IConnectionMultiplexer, string)

Section titled “ RedisEventStore(IConnectionMultiplexer, string)”

Initializes a new instance of the class.

public RedisEventStore(IConnectionMultiplexer multiplexer, string keyPrefix = "cephalon:")

multiplexer IConnectionMultiplexer

The Redis connection multiplexer.

keyPrefix string

The key prefix applied to all stream keys (e.g. “cephalon:”).

AppendAsync(string, IReadOnlyCollection<IDomainEvent>, long, CancellationToken)

Section titled “ AppendAsync(string, IReadOnlyCollection<IDomainEvent>, long, CancellationToken)”

Appends one or more events to the requested stream after checking the expected version.

public Task AppendAsync(string streamId, IReadOnlyCollection<IDomainEvent> events, long expectedVersion, CancellationToken cancellationToken = default)

streamId string

The stable stream identifier.

events IReadOnlyCollection<IDomainEvent>

The events to append.

expectedVersion long

The current stream version expected by the caller. Use -1 to require a brand-new stream.

cancellationToken CancellationToken

The token that cancels the operation.

Task

A task that completes when the append finishes.

GetVersionAsync(string, CancellationToken)

Section titled “ GetVersionAsync(string, CancellationToken)”

Gets the latest version known for the requested stream.

public Task<long> GetVersionAsync(string streamId, CancellationToken cancellationToken = default)

streamId string

The stable stream identifier.

cancellationToken CancellationToken

The token that cancels the operation.

Task<long>

A task that returns the current stream version, or -1 when the stream does not exist.

ReadStreamAsync(string, long, CancellationToken)

Section titled “ ReadStreamAsync(string, long, CancellationToken)”

Reads the requested stream from the supplied version onward.

public IAsyncEnumerable<IDomainEvent> ReadStreamAsync(string streamId, long fromVersion = 0, CancellationToken cancellationToken = default)

streamId string

The stable stream identifier.

fromVersion long

The first stream version to include. The default is 0.

cancellationToken CancellationToken

The token that cancels the operation.

IAsyncEnumerable<IDomainEvent>

An async sequence of domain events in ascending stream-version order.