fix hangfire切换到redis
This commit is contained in:
@@ -19,10 +19,9 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.7" />
|
||||
<PackageReference Include="Hangfire.Dashboard.BasicAuthorization" Version="1.0.2" />
|
||||
<PackageReference Include="Hangfire.MySqlStorage" Version="2.0.3" />
|
||||
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.3" />
|
||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.5.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.26" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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"
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ using System.Net.NetworkInformation;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.Startup;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using StackExchange.Redis;
|
||||
using static StackExchange.Redis.Role;
|
||||
|
||||
class Program
|
||||
{
|
||||
@@ -22,6 +24,12 @@ public class Startup : DefaultStartup
|
||||
{
|
||||
base.ConfigureServices(services);
|
||||
|
||||
services.AddSingleton<IConnectionMultiplexer>(sp =>
|
||||
{
|
||||
return ConnectionMultiplexer.Connect("192.168.199.30:30115,defaultDatabase:1,password=zxc111");
|
||||
});
|
||||
|
||||
|
||||
var p = new Ping();
|
||||
Console.WriteLine(p.Send("192.168.199.124").Status);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user