GobanSource.Bus.Redis
1.0.54
Prefix Reserved
dotnet add package GobanSource.Bus.Redis --version 1.0.54
NuGet\Install-Package GobanSource.Bus.Redis -Version 1.0.54
<PackageReference Include="GobanSource.Bus.Redis" Version="1.0.54" />
<PackageVersion Include="GobanSource.Bus.Redis" Version="1.0.54" />
<PackageReference Include="GobanSource.Bus.Redis" />
paket add GobanSource.Bus.Redis --version 1.0.54
#r "nuget: GobanSource.Bus.Redis, 1.0.54"
#:package GobanSource.Bus.Redis@1.0.54
#addin nuget:?package=GobanSource.Bus.Redis&version=1.0.54
#tool nuget:?package=GobanSource.Bus.Redis&version=1.0.54
GobanSource.Bus.Redis
A lightweight, Redis-based message bus library for .NET applications. Enables communication between distributed application instances using Redis Pub/Sub.
Features
- True Fan-Out Messaging: Each message is delivered to all active subscribers across different application instances
- Instance Filtering: Messages from the same instance are automatically skipped
- Type-Safe Message Handling: Generic interfaces for strongly-typed message processing
- Optional LZ4 Compression: Reduce bandwidth usage with fast LZ4 compression (backward compatible)
- No Message Persistence: Only active subscribers receive messages (suitable for cache synchronization)
- Easy Integration: Works with .NET's dependency injection and hosted services
Installation
dotnet add package GobanSource.Bus.Redis
Requirements
- .NET Standard 2.0+
- Redis server
Quick Start
1. Define your message type
public class SimpleMessage : BaseMessage
{
public string Data { get; set; } = null!;
}
2. Create a message handler
public class SimpleMessageHandler : IMessageHandler<SimpleMessage>
{
private readonly ILogger<SimpleMessageHandler> _logger;
public SimpleMessageHandler(ILogger<SimpleMessageHandler> logger)
{
_logger = logger;
}
public async Task HandleAsync(SimpleMessage message)
{
_logger.LogInformation("Received message: {Data}", message.Data);
// Process the message here
await Task.CompletedTask;
}
}
3. Register services in your application
// Add Redis connection
services.AddSingleton<IConnectionMultiplexer>(sp =>
ConnectionMultiplexer.Connect("localhost:6379"));
// Register the message bus for SimpleMessage
services.AddTransient<IRedisSyncBus<SimpleMessage>>(sp => new RedisSyncBus<SimpleMessage>(
sp.GetRequiredService<IConnectionMultiplexer>(),
"messages", // Channel prefix
sp.GetRequiredService<ILogger<RedisSyncBus<SimpleMessage>>>(),
false)); // Enable compression (optional, defaults to false)
// Register the message handler
services.AddTransient<IMessageHandler<SimpleMessage>, SimpleMessageHandler>();
// Register the hosted service that connects the bus to the handler
services.AddHostedService<MessageSyncHostedService<SimpleMessage>>();
4. Publish messages
public class MessagePublisher
{
private readonly IRedisSyncBus<SimpleMessage> _bus;
public MessagePublisher(IRedisSyncBus<SimpleMessage> bus)
{
_bus = bus;
}
public async Task SendMessageAsync(string data)
{
await _bus.PublishAsync(new SimpleMessage
{
Data = data
});
}
}
Compression
GobanSource.Bus.Redis supports optional LZ4 compression to reduce bandwidth usage and improve performance for large messages.
Enabling Compression
// Enable compression when creating the bus
services.AddTransient<IRedisSyncBus<SimpleMessage>>(sp => new RedisSyncBus<SimpleMessage>(
sp.GetRequiredService<IConnectionMultiplexer>(),
"messages",
sp.GetRequiredService<ILogger<RedisSyncBus<SimpleMessage>>>(),
enableCompression: true)); // Enable LZ4 compression
Features
- LZ4 Frame Format: Fast compression/decompression with good compression ratios
- Automatic Detection: Compressed and uncompressed messages are automatically detected
- Backward Compatibility: Applications with compression enabled can communicate with those without
- Performance Benefits: Especially effective for repetitive content or large messages
- Transparent Operation: No changes needed to message handlers or publishers
When to Use Compression
- Large Messages: Messages over 1KB typically benefit from compression
- Repetitive Content: JSON with repeated structures compress very well
- High-Volume Applications: Reduces Redis bandwidth and network traffic
- Mixed Environments: Safe to enable during gradual rollouts
How It Works
GobanSource.Bus.Redis uses Redis Pub/Sub channels to publish and subscribe to messages between different application instances. When a message is published:
- The message is serialized to JSON
- If compression is enabled, the JSON is compressed using LZ4 Frame format
- The message (compressed or uncompressed) is published to a Redis channel:
{prefix}:{messageType} - Redis broadcasts the message to all subscribers of that channel
- Each subscriber automatically detects and decompresses the message if needed
- Messages from the same instance (identified by InstanceId) are automatically skipped
License
This project is licensed under the MIT License.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Used By
- PushToDisplay — an API-first real-time display board platform that pushes content to any screen via REST API, CLI, GitHub Action, or MCP server. Uses GobanSource.Bus.Redis for cross-instance cache synchronization in its .NET 10 microservices backend.
Acknowledgments
- Built and maintained by Goban Source
| 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 is compatible. 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
- K4os.Compression.LZ4.Streams (>= 1.3.8)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- StackExchange.Redis (>= 2.8.24)
- ZstdSharp.Port (>= 0.8.5)
-
net9.0
- K4os.Compression.LZ4.Streams (>= 1.3.8)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- StackExchange.Redis (>= 2.8.24)
- ZstdSharp.Port (>= 0.8.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on GobanSource.Bus.Redis:
| Package | Downloads |
|---|---|
|
GobanSource.ReplicatedLruCache
A lightweight, replicated LRU cache library for .NET applications. replicated by redis pub/sub. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.54 | 142 | 6/3/2026 |
| 1.0.52 | 1,070 | 5/12/2026 |
| 1.0.50 | 119 | 5/12/2026 |
| 1.0.47 | 1,938 | 11/23/2025 |
| 1.0.44 | 503 | 7/11/2025 |
| 1.0.42 | 612 | 6/16/2025 |
| 1.0.40 | 256 | 6/15/2025 |
| 1.0.38 | 336 | 6/14/2025 |
| 0.1.2.29 | 371 | 6/13/2025 |
| 0.1.2.26 | 238 | 4/25/2025 |
| 0.1.2.23 | 287 | 4/15/2025 |
| 0.1.2.21 | 288 | 4/15/2025 |
| 0.1.2.19-pre | 293 | 4/15/2025 |
| 0.1.2.17 | 295 | 4/15/2025 |
| 0.1.2.16 | 294 | 4/14/2025 |
| 0.1.2 | 298 | 4/14/2025 |
| 0.1.1 | 316 | 4/14/2025 |
| 0.1.0 | 245 | 4/12/2025 |