mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 17:57:21 +01:00
more redis fixes
This commit is contained in:
parent
3cdaa53a65
commit
56728d1fba
4 changed files with 21 additions and 8 deletions
|
|
@ -137,7 +137,7 @@ namespace MareSynchronosServer
|
|||
services.AddStackExchangeRedisCache(opt =>
|
||||
{
|
||||
opt.Configuration = redis;
|
||||
opt.InstanceName = "MareSynchronos";
|
||||
opt.InstanceName = "MareSynchronosCache:";
|
||||
});
|
||||
services.AddSingleton<IClientIdentificationService, DistributedClientIdentificationService>();
|
||||
services.AddHostedService(p => p.GetService<IClientIdentificationService>());
|
||||
|
|
|
|||
|
|
@ -690,7 +690,9 @@ public class DiscordBot : IHostedService
|
|||
updateStatusCts = new();
|
||||
while (!updateStatusCts.IsCancellationRequested)
|
||||
{
|
||||
await discordClient.SetActivityAsync(new Game("Mare for " + clientService.GetOnlineUsers() + " Users")).ConfigureAwait(false);
|
||||
var onlineUsers = clientService.GetOnlineUsers();
|
||||
logger.LogInformation("Users online: " + onlineUsers);
|
||||
await discordClient.SetActivityAsync(new Game("Mare for " + onlineUsers + " Users")).ConfigureAwait(false);
|
||||
await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class Startup
|
|||
services.AddStackExchangeRedisCache(opt =>
|
||||
{
|
||||
opt.Configuration = redis;
|
||||
opt.InstanceName = "MareSynchronos";
|
||||
opt.InstanceName = "MareSynchronosCache:";
|
||||
});
|
||||
services.AddSingleton<IClientIdentificationService, DistributedClientIdentificationService>();
|
||||
services.AddHostedService(p => p.GetService<IClientIdentificationService>());
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using MareSynchronosShared.Metrics;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace MareSynchronosShared.Services;
|
||||
|
|
@ -9,21 +10,31 @@ namespace MareSynchronosShared.Services;
|
|||
public class DistributedClientIdentificationService : BaseClientIdentificationService
|
||||
{
|
||||
private readonly IDistributedCache distributedCache;
|
||||
private readonly ILogger<DistributedClientIdentificationService> logger;
|
||||
private readonly IConfiguration configuration;
|
||||
private const string RedisPrefix = "uidcache:";
|
||||
|
||||
public DistributedClientIdentificationService(MareMetrics metrics, IDistributedCache distributedCache, IConfiguration configuration) : base(metrics)
|
||||
public DistributedClientIdentificationService(MareMetrics metrics, IDistributedCache distributedCache, IConfiguration configuration, ILogger<DistributedClientIdentificationService> logger) : base(metrics)
|
||||
{
|
||||
this.distributedCache = distributedCache;
|
||||
this.logger = logger;
|
||||
this.configuration = configuration.GetSection("MareSynchronos");
|
||||
}
|
||||
|
||||
public override int GetOnlineUsers()
|
||||
{
|
||||
var redis = configuration.GetValue<string>("RedisConnectionString");
|
||||
var conn = ConnectionMultiplexer.Connect(redis);
|
||||
var endpoint = conn.GetEndPoints().First();
|
||||
return conn.GetServer(endpoint).Keys(pattern: RedisPrefix + "*").Count();
|
||||
try
|
||||
{
|
||||
var redis = configuration.GetValue<string>("RedisConnectionString");
|
||||
var conn = ConnectionMultiplexer.Connect(redis);
|
||||
var endpoint = conn.GetEndPoints().First();
|
||||
return conn.GetServer(endpoint).Keys(pattern: "*" + RedisPrefix + "*").Count();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Error during GetOnlineUsers");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override string? GetCharacterIdentForUid(string uid)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue