Add Redis, Wal, Services
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user