29 lines
863 B
C#
29 lines
863 B
C#
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);
|
|
}
|
|
}
|