Yarkool.Hangfire.Redis.SharpRedis 0.0.1

dotnet add package Yarkool.Hangfire.Redis.SharpRedis --version 0.0.1                
NuGet\Install-Package Yarkool.Hangfire.Redis.SharpRedis -Version 0.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Yarkool.Hangfire.Redis.SharpRedis" Version="0.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Yarkool.Hangfire.Redis.SharpRedis --version 0.0.1                
#r "nuget: Yarkool.Hangfire.Redis.SharpRedis, 0.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Yarkool.Hangfire.Redis.SharpRedis as a Cake Addin
#addin nuget:?package=Yarkool.Hangfire.Redis.SharpRedis&version=0.0.1

// Install Yarkool.Hangfire.Redis.SharpRedis as a Cake Tool
#tool nuget:?package=Yarkool.Hangfire.Redis.SharpRedis&version=0.0.1                

Yarkool.Hangfire.Redis

Hangfire 的 Redis 实现, 支持 FreeRedisSharpRedis

教程

创建 Storage, 如果使用 FreeRedis 则引入 Yarkool.Hangfire.Redis.FreeRedis, 使用 SharpRedis 则引入 Yarkool.Hangfire.Redis.SharpRedis

// Redis 链接字符串
var  redisConn = "127.0.0.1,port=6379"

// FreeRedis
var redisClient = new FreeRedisClient(new RedisClient(redisConn)); 

// SharpRedis
var redisClient = new SharpRedisClient(global::SharpRedis.Redis.UseStandalone($"host={redisConn}"));

// 创建 Storage
var storage = new RedisStorage(redisClient, new RedisStorageOptions { Prefix = "hangfire:" });
builder.Services.AddHangfire(o => o.UseStorage(storage));
builder.Services.AddHangfireServer((sp) =>
{
    sp.Queues =
    [
        "dev",
        "test",
        "pred",
        "prod",
        "default"
    ];
});

// 使用方式

// 添加任务
RecurringJob.AddOrUpdate("test_console", () => Console.WriteLine($"定时任务输出: {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}"), "*/1 * * * * ? ", new RecurringJobOptions { TimeZone = TimeZoneInfo.Local });

// 或者使用注入方式
[ApiController]
[Route("[controller]")]
public class MessageController
(
    IBackgroundJobClient backgroundJobClient
) : ControllerBase
{    
    [HttpPost(Name = "Push")]
    public string Push()
    {
        _backgroundJobClient.Enqueue(() => Console.WriteLine($"推送测试: {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}"));
        return "success";
    }
}
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.0.1 54 2/11/2025