fix hangfire切换到redis

This commit is contained in:
2024-01-30 17:19:00 +08:00
parent 7e90058587
commit 2a432088aa
3 changed files with 18 additions and 12 deletions

View File

@@ -1,8 +1,8 @@
using Hangfire;
using Hangfire.Dashboard.BasicAuthorization;
using Hangfire.MySql;
using Hangfire.Redis.StackExchange;
using Kurisu.AspNetCore.Startup;
using StackExchange.Redis;
namespace Dlhis.ScheduledTask.Packs;
@@ -14,16 +14,15 @@ public class HangfirePack : BaseAppPack
public override void ConfigureServices(IServiceCollection services)
{
services.AddHangfire(configuration =>
services.AddHangfire((sp, config) =>
{
var options = new MySqlStorageOptions
{
TablesPrefix = "hangfire"
};
configuration.UseSimpleAssemblyNameTypeSerializer()
config.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseStorage(new MySqlStorage(Configuration.GetConnectionString("HangfireConnection"), options));
.UseRedisStorage(sp.GetService<IConnectionMultiplexer>(), new RedisStorageOptions
{
Db = 5,
Prefix = "hangfire"
});
});