MeVitae.RedisWorkQueue
0.1.5
See the version list below for details.
dotnet add package MeVitae.RedisWorkQueue --version 0.1.5
NuGet\Install-Package MeVitae.RedisWorkQueue -Version 0.1.5
<PackageReference Include="MeVitae.RedisWorkQueue" Version="0.1.5" />
<PackageVersion Include="MeVitae.RedisWorkQueue" Version="0.1.5" />
<PackageReference Include="MeVitae.RedisWorkQueue" />
paket add MeVitae.RedisWorkQueue --version 0.1.5
#r "nuget: MeVitae.RedisWorkQueue, 0.1.5"
#addin nuget:?package=MeVitae.RedisWorkQueue&version=0.1.5
#tool nuget:?package=MeVitae.RedisWorkQueue&version=0.1.5
RedisWorkQueue: Dotnet Implementation
A work queue, on top of a redis database, with implementations in Python, Rust, Go, Node.js (TypeScript) and Dotnet (C#).
This is the Dotnet implementations. For an overview of how the work queue works, it's limitations, and the general concepts and implementations in other languages, please read the redis-work-queue readme.
Documentation
Below is a brief overview and an example. More details on the core concepts can be found in the readme, and full API documentation can be found in ../RedisWorkQueue.pdf.
WorkQueue
The WorkQueue
class represents a work queue backed by a Redis database. It provides methods to add
items to the queue, lease items from the queue, and mark completed items as done.
Properties
Session
: Gets or sets the unique identifier for the current session.
Methods
AddItem(IRedisClient db, Item item)
: Adds an item to the work queue. Thedb
parameter is the Redis instance and theitem
parameter is the item to be added.QueueLength(IRedisClient db)
: Gets the length of the main queue. Thedb
parameter is the Redis instance.Processing(IRedisClient db)
: Gets the length of the processing queue. Thedb
parameter is the Redis instance.LeaseExists(IRedisClient db, string itemId)
: Checks if a lease exists for the specified item ID. Thedb
parameter is the Redis instance and theitemId
parameter is the ID of the item to check.Lease(IRedisClient db, int leaseSeconds, bool block, int timeout = 0)
: Requests a work lease from the work queue. This should be called by a worker to get work to complete. Thedb
parameter is the Redis instance, theleaseSeconds
parameter is the number of seconds to lease the item for, theblock
parameter indicates whether to block and wait for an item to be available if the main queue is empty, and thetimeout
parameter is the maximum time to block in milliseconds.Complete(IRedisClient db, Item item)
: Marks a job as completed and removes it from the work queue. Thedb
parameter is the Redis instance and theitem
parameter is the item to be completed.
Example Usage
using FreeRedis;
using RedisWorkQueue;
var redis = new RedisClient("localhost");
var workQueue = new WorkQueue("work_queue");
var item = new Item(Encoding.UTF8.GetBytes("data"), "item_1");
workQueue.AddItem(redis, item);
var queueLength = workQueue.QueueLength(redis);
Console.WriteLine($"Queue Length: {queueLength}");
var lease = workQueue.Lease(redis, 30, true, 10000);
if (lease != null)
{
Console.WriteLine($"Leased Item: {lease.ID}");
// Do the work here
workQueue.Complete(redis, lease);
}
else
{
Console.WriteLine("No item available to lease");
}
In this example, we create a Redis client and a new instance of the WorkQueue
class. We then add
an item to the work queue using the AddItem
method and get the length of the main queue using the
QueueLength
method.
We then try to lease an item from the work queue using the Lease
method. If an item is available,
we do the work and mark the item as completed using the Complete
method.
Note that in this example, we pass true
for the block
parameter of the Lease
method, which
means the method will block and wait for an item to be available if the main queue is empty. We also
pass a timeout
value of 10000
milliseconds, which means that if there are no items available
after 10 seconds, the method will return null
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- FreeRedis (>= 1.1.5)
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- FreeRedis (>= 1.1.5)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.