EasyCore.RedisStreams
8.0.0
dotnet add package EasyCore.RedisStreams --version 8.0.0
NuGet\Install-Package EasyCore.RedisStreams -Version 8.0.0
<PackageReference Include="EasyCore.RedisStreams" Version="8.0.0" />
<PackageVersion Include="EasyCore.RedisStreams" Version="8.0.0" />
<PackageReference Include="EasyCore.RedisStreams" />
paket add EasyCore.RedisStreams --version 8.0.0
#r "nuget: EasyCore.RedisStreams, 8.0.0"
#:package EasyCore.RedisStreams@8.0.0
#addin nuget:?package=EasyCore.RedisStreams&version=8.0.0
#tool nuget:?package=EasyCore.RedisStreams&version=8.0.0
π΄ EasyCore.RedisStreams
EasyCore.RedisStreams is a Redis Streams infrastructure client for .NET 8. Built on StackExchange.Redis, it provides DI registration, connect, consumer-group subscribe/ack, and a unified entry format (
RedisHeader/type/payload). It is not tied toIEvent/ EventBus β use it standalone, or via theEasyCore.EventBus.RedisStreamsadapter.
π Language
- Chinese: README.md
- English (this document)
π Table of Contents
- 1. Positioning
- 2. Relation to EventBus
- 3. Requirements
- 4. Installation
- 5. Quick Start
- 6. Message Format (
RedisStreamMessageFormat) - 7. API Overview
- 8. Options (
RedisStreamsOptions) - 9. FAQ
- 10. License
1. π― Positioning
| Scenario | Fit? |
|---|---|
| Publish/subscribe on Redis stream keys | β |
| Consumer groups + acknowledge | β |
Unified type + JSON payload + retry header |
β |
Unified IEvent + handler discovery (EDA) |
β β use EasyCore.EventBus.RedisStreams |
| In-process local events | β β use EasyCore.EventBus local bus |
1.1 Design Principles
| Principle | Meaning |
|---|---|
| Infrastructure layer | EndPoints, consumer groups, and stream entry fields |
| Standalone | No dependency on the EasyCore.EventBus core package |
| Clear wire format | Fixed field names in RedisStreamMessageFormat |
| Adapter-friendly | The EventBus RedisStreams adapter reuses this client |
2. Relation to EventBus
βββββββββββββββββββββββββββββββ
β App code (JSON payload) β
ββββββββββββββββ¬βββββββββββββββ
β IRedisStreamsClient
βΌ
βββββββββββββββββββββββββββββββ
β EasyCore.RedisStreams (this)β β infrastructure client
ββββββββββββββββ¬βββββββββββββββ
β StackExchange.Redis
βΌ
Redis
βββββββββββββββββββββββββββββββ
β EasyCore.EventBus.RedisStreams β β adapter: IEvent / Handler
β βββ uses this client β
βββββββββββββββββββββββββββββββ
| Package | Role |
|---|---|
EasyCore.RedisStreams |
Generic Redis Streams client (this package) |
EasyCore.EventBus.RedisStreams |
Maps EventBus IEvent onto Redis Streams |
3. β Requirements
| Item | Requirement |
|---|---|
| .NET | 8.0+ |
| Dependency | StackExchange.Redis 2.8.x (brought by this package) |
| Redis | Instance with Streams support (Redis 5.0+) |
4. π₯ Installation
dotnet add package EasyCore.RedisStreams
5. β‘ Quick Start
5οΈβ£.1οΈβ£ Register DI
using EasyCore.RedisStreams;
builder.Services.EasyCoreRedisStreams(o =>
{
o.EndPoints = new List<string> { "localhost:6379" };
o.User = null; // ACL user (optional)
o.Password = null; // password (optional)
o.ConnectTimeout = 10; // seconds
o.SyncTimeout = 10; // seconds
o.DefaultDatabase = 0;
o.ConsumerGroup = "RedisGroup";
o.AppName = "MyApp";
});
5οΈβ£.2οΈβ£ Publish
public sealed class NotifyPublisher
{
private readonly IRedisStreamsClient _client;
public NotifyPublisher(IRedisStreamsClient client) => _client = client;
public async Task PublishAsync(string userId, CancellationToken ct = default)
{
await _client.ConnectAsync(ct);
var payload = $$"""{"userId":"{{userId}}","channel":"sms"}""";
var header = new RedisStreamHeader
{
RetryCount = 0,
RetryInterval = 5
};
await _client.PublishAsync(
streamKey: "notify:sms",
typeName: "SmsNotify",
payloadJson: payload,
header: header,
cancellationToken: ct);
}
}
5οΈβ£.3οΈβ£ Subscribe and Acknowledge
public sealed class NotifyConsumer : BackgroundService
{
private readonly IRedisStreamsClient _client;
public NotifyConsumer(IRedisStreamsClient client) => _client = client;
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _client.ConnectAsync(stoppingToken);
await _client.SubscribeAsync(
streamKeys: new[] { "notify:sms" },
handler: async (msg, ct) =>
{
// msg.TypeName / msg.PayloadJson / msg.Header
// handle businessβ¦
await _client.AcknowledgeAsync(msg.StreamKey, msg.MessageId, ct);
},
cancellationToken: stoppingToken);
}
}
RedisStreamsDeliveredMessage fields: StreamKey, MessageId, TypeName, PayloadJson, Header.
6. Message Format (RedisStreamMessageFormat)
Each stream entry uses fixed field names:
| Constant | Redis field | Content |
|---|---|---|
HeaderField |
RedisHeader |
JSON of RedisStreamHeader |
TypeField |
type |
Logical message type name |
PayloadField |
payload |
Business JSON payload |
RedisStreamHeader:
| Property | Description |
|---|---|
RetryCount |
Times processing has been retried |
RetryInterval |
Retry interval (unit agreed by the EventBus integration layer) |
When header is null, publish writes a default header.
7. π§© API Overview
| Member | Description |
|---|---|
EasyCoreRedisStreams(Action<RedisStreamsOptions>) |
DI: Options and IRedisStreamsClient |
ConnectAsync |
Connect to Redis and prepare the consumer group name |
PublishAsync(streamKey, typeName, payloadJson, header?) |
XADD with unified fields |
SubscribeAsync(streamKeys, handler) |
Consumer-group consume loop |
AcknowledgeAsync(streamKey, messageId) |
XACK the entry |
IRedisStreamsClient implements IAsyncDisposable β dispose on shutdown.
8. Options (RedisStreamsOptions)
| Property | Type | Default | Description |
|---|---|---|---|
EndPoints |
List<string> |
empty | Redis endpoints, e.g. localhost:6379 |
User |
string? |
null |
ACL username |
Password |
string? |
null |
Password |
ConnectTimeout |
int |
10 |
Connect timeout (seconds, Γ1000 internally) |
SyncTimeout |
int |
10 |
Sync timeout (seconds, Γ1000 internally) |
AbortOnConnectFail |
bool |
false |
Abort when initial connect fails |
DefaultDatabase |
int |
0 |
Default DB index |
ConsumerGroup |
string |
RedisGroup |
Group name suffix (combined with AppName) |
AppName |
string? |
null |
Group name prefix; entry assembly when null |
ToConfigurationOptions() converts these settings to StackExchange.Redis.ConfigurationOptions.
9. β FAQ
Q: This package vs EasyCore.EventBus.RedisStreams?
A: Use the EventBus adapter for IEvent, handlers, and retries. Use this package for stream-key + JSON I/O.
Q: Why fixed RedisHeader / type / payload?
A: So multiple services (and the EventBus adapter) can share the same stream layout.
Q: Is ConnectTimeout in milliseconds?
A: No β Options use seconds; values are multiplied by 1000 for StackExchange.Redis.
Q: Do I need to create the consumer group myself?
A: The client prepares the group during subscribe. Ensure Redis supports Streams and the key is consumable.
Q: Cluster / sentinel?
A: Put endpoints in EndPoints with credentials as needed; advanced topologies follow StackExchange.Redis docs.
10. π License
MIT OR Apache-2.0 β see the repository LICENSE if present, or the NuGet package metadata.
π€ Contributing
Issues and PRs are welcome. After changing this package, verify EasyCore.EventBus.RedisStreams and related demos.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- StackExchange.Redis (>= 2.8.31)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on EasyCore.RedisStreams:
| Package | Downloads |
|---|---|
|
EasyCore.EventBus.RedisStreams
.NET Core EventBus distributed transport based on Redis Streams. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.0 | 0 | 7/18/2026 |