Skip to content

Commit

Permalink
fix: 修复 Redis 监控API 获取服务队列失败问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jianxuanbing committed Sep 28, 2020
1 parent 289de8c commit a382b0a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Hangfire.Redis.CSRedisCore
Hangfire.Redis.CSRedis
Hangfire Redis 存储基于 [Hangfire.Redis.StackExchange](https://github.com/marcoCasamento/Hangfire.Redis.StackExchange),但使用的是 [CSRedisCore](https://github.com/2881099/csredis) 组件作为访问客户端。

## 教程:在ASP.NET Core MVC 使用Hangfire Redis存储
### 入门
要在 ASP.NET Core MVC 项目中使用Hangfire的Redis存储。首先,您至少需要安装这两个软件包:
2 changes: 1 addition & 1 deletion samples/Hangfire.Redis.Sample/Hangfire.Redis.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<ServerGarbageCollection>false</ServerGarbageCollection>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
Expand Down
9 changes: 6 additions & 3 deletions samples/Hangfire.Redis.Sample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void ConfigureServices(IServiceCollection services)
{
var storage = new RedisStorage("127.0.0.1:6379,defaultDatabase=1,poolsize=50", new RedisStorageOptions
{
Prefix = "hangfire.dev"
Prefix = "hangfire.dev:"
});
services.AddHangfire(o => { o.UseStorage(storage); });
JobStorage.Current = storage;
Expand Down Expand Up @@ -57,8 +57,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
DisplayStorageConnectionString = false, // 是否显示数据库连接信息
IsReadOnlyFunc = context => false,
});
app.UseHangfireServer();
RecurringJob.AddOrUpdate(() => Debug.WriteLine($"输出内容:{DateTime.Now:yyyy-MM-dd HH:mm:ss.sss}"), "*/1 * * * * ? ", TimeZoneInfo.Local);
app.UseHangfireServer(new BackgroundJobServerOptions
{
Queues = new []{"dev","test","pred","prod","default"}
});
RecurringJob.AddOrUpdate(() => Console.WriteLine($"输出内容:{DateTime.Now:yyyy-MM-dd HH:mm:ss.sss}"), "*/1 * * * * ? ", TimeZoneInfo.Local);
}
}
}
2 changes: 1 addition & 1 deletion src/Hangfire.Redis.CSRedisCore/RedisMonitoringApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public IList<ServerDto> Servers() =>

foreach (var serverName in serverNames)
{
var queue = redis.LRange(_storage.GetRedisKey($"server:{serverName}:queues"), 1, -1);
var queue = redis.LRange(_storage.GetRedisKey($"server:{serverName}:queues"), 0, -1);

var server = redis.HMGet(_storage.GetRedisKey($"server:{serverName}"), new string[] { "WorkerCount", "StartedAt", "Heartbeat" });
if (server[0] == null)
Expand Down

0 comments on commit a382b0a

Please sign in to comment.