|
|
@@ -135,15 +135,12 @@ export function setupExamEvents({ socket, apiClient }: Variables) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 存储当前问题状态
|
|
|
- await apiClient.database.table('exam_questions').insert({
|
|
|
- room_id: roomId,
|
|
|
- question_id: 'current_state',
|
|
|
- date: question.date,
|
|
|
- price: question.price,
|
|
|
- created_at: apiClient.database.fn.now(),
|
|
|
- updated_at: apiClient.database.fn.now()
|
|
|
- });
|
|
|
+ // 存储当前问题状态到Redis
|
|
|
+ const questionKey = `exam:${roomId}:current_question`;
|
|
|
+ await apiClient.redis.hset(questionKey, 'date', String(question.date));
|
|
|
+ await apiClient.redis.hset(questionKey, 'price', String(question.price));
|
|
|
+ await apiClient.redis.hset(questionKey, 'updated_at', new Date().toISOString());
|
|
|
+ // TODO: 需要Redis服务端配置自动过期或通过其他方式实现TTL
|
|
|
|
|
|
// 广播题目到房间
|
|
|
socket.to(roomId).emit('exam:question', {
|