Yardios.RedisQueue
0.4.1
dotnet add package Yardios.RedisQueue --version 0.4.1
NuGet\Install-Package Yardios.RedisQueue -Version 0.4.1
<PackageReference Include="Yardios.RedisQueue" Version="0.4.1" />
<PackageVersion Include="Yardios.RedisQueue" Version="0.4.1" />
<PackageReference Include="Yardios.RedisQueue" />
paket add Yardios.RedisQueue --version 0.4.1
#r "nuget: Yardios.RedisQueue, 0.4.1"
#:package Yardios.RedisQueue@0.4.1
#addin nuget:?package=Yardios.RedisQueue&version=0.4.1
#tool nuget:?package=Yardios.RedisQueue&version=0.4.1
Yardios.RedisQueue
Yardios.RedisQueue is a Redis-backed queue system for .NET 8+, inspired by Laravel's queue system. Easily enqueue jobs into Redis and process them using background workers.
✨ Features
- Queue any
IJob
into Redis - Process jobs asynchronously with background workers
- Dependency injection & configuration support
- Retry logic & failure handling
- Delayed job support
- Specify queue names per job
- Inspired by Laravel's queue system
📦 Installation
Add via CLI:
dotnet add package Yardios.RedisQueue
Or via .csproj
:
<PackageReference Include="Yardios.RedisQueue" Version="0.4.1" />
🛠️ Usage
1️⃣ Register the Redis Queue
In your Program.cs
:
var builder = WebApplication.CreateBuilder(args);
// Add RedisQueue using IConfiguration (appsettings.json)
builder.Services.AddRedisQueue(builder.Configuration);
var app = builder.Build();
app.Run();
In your appsettings.json
:
{
"Redis": {
"ConnectionString": "localhost:6379"
},
"QueueProcessorOptions": {
"QueueNames": [ "default", "emails" ],
"JobRetryOptions": {
"MaxRetries": {
"Yardios.API.Application.Jobs.SendTeamInvite": 3
},
"FailUntilAttempt": {
"Yardios.API.Application.Jobs.SendTeamInvite": 2
}
}
},
"QueueWorkerOptions": {
"DelayMilliseconds": 1000
}
}
2️⃣ Create a Job
Implement the IJob
interface:
public class SendEmailJob : IJob
{
public string Email { get; set; }
public string Message { get; set; }
public async Task HandleAsync(IServiceProvider services, CancellationToken cancellationToken)
{
var emailService = services.GetRequiredService<IEmailService>();
await emailService.SendAsync(Email, Message);
}
}
3️⃣ Enqueue a Job (with Queue Name and Delay)
You can specify the queue name and an optional delay when enqueuing jobs:
await _queue.EnqueueAsync(new SendEmailJob
{
Email = "future@example.com",
Message = "This is a delayed job!"
}, queueName: "emails", delay: TimeSpan.FromSeconds(30));
queueName
(optional): The Redis queue to push the job onto. Must match one of theQueueNames
inappsettings.json
.delay
(optional): ATimeSpan
specifying how long to delay before processing the job.
Example without delay:
await _queue.EnqueueAsync(new SendEmailJob
{
Email = "test@example.com",
Message = "Hello!"
}, queueName: "default");
4️⃣ Dependency Injection Best Practices
✅ Always inject the IQueue
interface into your services — never inject the concrete RedisQueue
class directly.
This allows for better abstraction, future flexibility, and proper dependency resolution by the DI container.
For example, in your services:
public class TeamService : ITeamService
{
private readonly IQueue _queue;
public TeamService(IQueue queue)
{
_queue = queue;
}
// Use _queue.EnqueueAsync(...) in your methods
}
✅ Avoid injecting the RedisQueue
class directly:
// ❌ Do not do this
public class TeamService
{
public TeamService(RedisQueue queue) { }
}
This will cause runtime errors because RedisQueue
is registered under the interface IQueue
in the service collection.
🛠️ Configuration
- Redis connection info is specified in
appsettings.json
underRedis:ConnectionString
. - QueueProcessorOptions allows setting queue names.
- QueueJobOptions allows specifying per-job settings like
FailUntilAttempt
andMaxRetries
.
Example appsettings.json
:
{
"Redis": {
"ConnectionString": "localhost:6379"
},
"QueueProcessorOptions": {
"QueueNames": [ "default", "emails" ],
"JobRetryOptions": {
"MaxRetries": {
"Yardios.API.Application.Jobs.SendTeamInvite": 3
},
"FailUntilAttempt": {
"Yardios.API.Application.Jobs.SendTeamInvite": 2
}
}
},
"QueueWorkerOptions": {
"DelayMilliseconds": 5000
}
}
💡 Inspired By
- Laravel Queue System
📄 License
MIT License
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.Hosting.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- StackExchange.Redis (>= 2.8.37)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.