refactor(game): invalidate field-level read-model projections

This commit is contained in:
2026-08-09 16:25:52 +00:00
parent 791006de26
commit e81b2da282
10 changed files with 728 additions and 37 deletions
+21 -1
View File
@@ -1,5 +1,10 @@
import type { RedisConnector } from '@sammo-ts/infra';
import { buildGameEventChannel, type RealtimeEvent } from '@sammo-ts/common';
import {
buildGameEventChannel,
buildGameReadModelRevisionKey,
type RealtimeEvent,
type RealtimeReadModelChanges,
} from '@sammo-ts/common';
// 게임 서버의 실시간 이벤트를 Redis pub/sub 채널로 송신한다.
export const publishRealtimeEvent = async (
@@ -10,3 +15,18 @@ export const publishRealtimeEvent = async (
const channel = buildGameEventChannel(profileName);
await redis.publish(channel, JSON.stringify(event));
};
export const publishRealtimeReadModelChanges = async (
redis: RedisConnector['client'],
profileName: string,
changes: RealtimeReadModelChanges
): Promise<number> => {
const revision = await redis.incr(buildGameReadModelRevisionKey(profileName));
await publishRealtimeEvent(redis, profileName, {
type: 'readModelChanged',
at: new Date().toISOString(),
changes,
revision,
});
return revision;
};