Add Redis, Wal, Services

This commit is contained in:
dingo
2025-11-10 07:42:03 -05:00
parent 7339d537f9
commit 72bc097a71
8 changed files with 386 additions and 25 deletions
+5
View File
@@ -0,0 +1,5 @@
namespace Server.Persistence;
public interface IWalPublisher
{
Task PublishAsync(string type, ulong charId, ulong zoneId, object payload, long tickId);
}
+28
View File
@@ -0,0 +1,28 @@
using System.Text.Json;
using Server.Redis;
namespace Server.Persistence;
public sealed class WalPublisher : IWalPublisher
{
private readonly IRedisManager _redis;
public WalPublisher(IRedisManager redis) { _redis = redis; }
public async Task PublishAsync(string type, ulong charId, ulong zoneId, object payload, long tickId)
{
var ev = new
{
eventId = Guid.NewGuid().ToString("N"),
type,
charId,
zoneId,
tickId,
ts = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
payload = payload
};
var json = JsonSerializer.Serialize(ev);
await _redis.Db.StreamAddAsync("wal:game", new StackExchange.Redis.NameValueEntry[] {
new("data", json)
}, maxLength: 1_000_000, useApproximateMaxLength: true);
}
}