DotNop.Channels.Redis
1.0.26
dotnet add package DotNop.Channels.Redis --version 1.0.26
NuGet\Install-Package DotNop.Channels.Redis -Version 1.0.26
<PackageReference Include="DotNop.Channels.Redis" Version="1.0.26" />
<PackageVersion Include="DotNop.Channels.Redis" Version="1.0.26" />
<PackageReference Include="DotNop.Channels.Redis" />
paket add DotNop.Channels.Redis --version 1.0.26
#r "nuget: DotNop.Channels.Redis, 1.0.26"
#:package DotNop.Channels.Redis@1.0.26
#addin nuget:?package=DotNop.Channels.Redis&version=1.0.26
#tool nuget:?package=DotNop.Channels.Redis&version=1.0.26
DotNop.Channels.Redis
System.Threading.Channels implementation backed by Redis. RedisChannel<T> is a Channel<T> whose reader and writer
can live in different processes and share messages through a Redis key.
Installation
dotnet add package DotNop.Channels.Redis
Usage
using System.Threading.Channels;
using DotNop.Channels.Redis;
using StackExchange.Redis;
var cancellationToken = CancellationToken.None;
await using var cnn = await ConnectionMultiplexer.ConnectAsync("localhost:6379");
var db = cnn.GetDatabase();
using var channel = new RedisChannel<Message>(
"my-channel",
db,
new Utf8JsonRedisValueSerializer<Message>(),
new RedisChannelOptions(capacity: 100) { FullMode = BoundedChannelFullMode.Wait }
);
await channel.Writer.WriteAsync(new Message("hello"), cancellationToken);
channel.Writer.Complete();
await foreach (var msg in channel.Reader.ReadAllAsync(cancellationToken))
{
Console.WriteLine(msg.Text);
}
record Message(string Text);
RedisChannelReader<T> and RedisChannelWriter<T> can also be used on their own when producer and consumer are in
different processes.
Options
| Option | Type | Default | Description |
|---|---|---|---|
Capacity |
int |
unbounded | Maximum number of items; -1 or omitted means unbounded. |
FullMode |
BoundedChannelFullMode |
Wait |
Behavior of the writer when the channel is full. |
ExpireAfterCompletion |
TimeSpan |
TimeSpan.Zero |
How long the Redis keys are kept after the writer completes. |
ChannelSlidingExpiration |
TimeSpan |
TimeSpan.Zero |
Sliding expiration of the Redis keys, refreshed on read and write. |
TimeSpan.Zero means the keys never expire. When ExpireAfterCompletion is not set, completing the channel applies
ChannelSlidingExpiration instead. Readers created on their own take RedisChannelReaderOptions, which has only
ChannelSlidingExpiration.
new RedisChannelOptions(capacity) throws ArgumentOutOfRangeException for 0 or values below -1. A writer created
without options is unbounded.
Full modes
For a bounded channel the capacity check and the push run as one Redis script, so several writers (in one or many processes) never push past capacity.
FullMode |
TryWrite on a full channel |
|---|---|
Wait |
Returns false; WriteAsync waits until there is room. |
DropWrite |
Drops the new item and returns true. |
DropNewest |
Removes the newest stored item, then writes. |
DropOldest |
Writes, then removes the oldest stored item. |
Behavior
The reader and writer follow the System.Threading.Channels contract:
ReadAllAsyncremoves items as it yields them and keeps going until the channel is completed and empty.TryRead,TryPeekandTryWritenever throw on a closed channel; they returnfalse.WaitToReadAsyncreturnsfalseonce the channel is completed and empty;WaitToWriteAsyncreturnsfalseonce it is completed. If the channel was completed with an error, both throw aChannelClosedExceptioncarrying that error message, and so doReadAsyncandWriteAsync.Reader.Completionfinishes when the channel is completed and drained (or its keys expired throughChannelSlidingExpiration), and is faulted when the channel was completed with an error.- Completion is shared through Redis: completing any writer closes the channel for all readers and writers of that
channel, including ones created later. Writes are checked against completion atomically, so no writer can add items
after the channel is completed, and only the first
TryCompleteacross all writers returnstrue. The error is stored as its message, so completing with an exception whose message is empty counts as a normal completion. - The channel uses two keys: the list
<name>and the completion marker{<name>}.eof, kept in one Redis Cluster slot by the hash tag. A name that already has a hash tag keeps its own (orders{eu}→orders{eu}.eof). On a cluster, avoid names that contain}but no hash tag (such asa{}bora}b): there the two keys land in different slots. nullitems are allowed if the serializer supports them.- Many readers and writers may share one
IConnectionMultiplexer; disposing one removes only its own subscription.
Serializers
Utf8JsonRedisValueSerializer<T>—System.Text.Json, UTF-8 bytes.JsonRedisValueSerializer<T>—System.Text.Json, string.- Implement
IRedisValueSerializer<T>for a custom format.
Metrics
The DotNop.Channels.Redis meter publishes:
| Instrument | Type | Unit | Description |
|---|---|---|---|
dotnop.channels.redis.written.messages |
Counter | {message} |
Messages written. |
dotnop.channels.redis.read.messages |
Counter | {message} |
Messages read. |
dotnop.channels.redis.write.wait.duration |
Histogram | s |
Time a writer waited for room. |
dotnop.channels.redis.read.wait.duration |
Histogram | s |
Time a reader waited for a message. |
dotnop.channels.redis.queue.length |
Gauge | {message} |
Messages in each channel with a live reader. |
All instruments carry a channel tag; the gauge also carries db.namespace (the Redis database index). The gauge
reports each channel and database once, however many readers it has, and stops reporting a reader once it is disposed.
It never queries Redis during collection: it reports the last known length and refreshes it in the background, so a
value can lag by one collection interval, and a channel is omitted while Redis is unreachable.
Building
dotnet test --solution DotNop.Channels.Redis.slnx # requires Redis on 127.0.0.1:6379 (or set REDIS_CONNECTION); tests are skipped without it
dotnet pack src/DotNop.Channels.Redis/DotNop.Channels.Redis.csproj -c Release # package goes to artifacts/package/release
Versions come from Nerdbank.GitVersioning (version.json). Packages are published to nuget.org from v* tags; see
RELEASING.md.
3rd Party Libraries and Contributions
Runtime dependencies:
- StackExchange.Redis — Redis client (MIT).
- DotNext.Threading — async synchronization primitives (MIT).
Build and test tooling:
- Nerdbank.GitVersioning — versioning from git (MIT).
- JetBrains.Annotations — code annotations (MIT).
- Microsoft.CodeAnalysis.PublicApiAnalyzers — public API tracking (MIT).
- xUnit.net — test framework (Apache-2.0).
- MartinCostello.Logging.XUnit — test logging (Apache-2.0).
Contributions are welcome: open an issue or a pull request.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. net11.0 is compatible. |
-
net10.0
- DotNext.Threading (>= 6.12.1)
- StackExchange.Redis (>= 3.4.31)
-
net11.0
- DotNext.Threading (>= 6.12.1)
- StackExchange.Redis (>= 3.4.31)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.26 | 106 | 11/11/2026 |
| 1.0.20-preview | 94 | 11/11/2026 |