refactor(game): invalidate field-level read-model projections
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user