Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE -#93] 캐싱된 퀴즈 확인 및 문제 개수 저장 #94

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

glaxyt
Copy link
Collaborator

@glaxyt glaxyt commented Nov 20, 2024

#️⃣연관된 이슈

#93 캐싱된 퀴즈 확인 및 문제 개수 저장

📝작업 내용


  @SubscribeMessage('master entry')
  async handleMasterEntry(client: Socket, payload: any) {
    // 방장이 게임을 나가도 재접속이 가능하며, 게임은 지속된다.
    const { classId } = payload;

    // 방장의 세션 ID와 핀코드를 생성
    const masterSid = uuidv4();
    const pinCode = uuidv4().slice(0, 6); // 메소드 분리해서 중복 확인하고 없을 때까지 반복

    client.join(pinCode); // pinCode로 되어 있는 roomd을 들어감

    this.redisService.set(`master_sid=${masterSid}`, JSON.stringify({ pinCode }));

    const quizData = await this.storeQuizToRedis(classId);
    const quizMaxNum = quizData.length;

    // 퀴즈 개수를 저장.
    const gameInfo = { classId, currentOrder: 0, quizMaxNum, participantList: [] };

    // 게임 정보를 저장
    this.redisService.set(`gameId=${pinCode}`, JSON.stringify(gameInfo));

    client.emit('session', masterSid);
    client.emit('pincode', pinCode);
  }

  private async storeQuizToRedis(classId: number) {
    const cachedQuizData = await this.redisService.get(`classId=${classId}`);

    if (cachedQuizData) {
      const quizData = JSON.parse(cachedQuizData);
      return quizData;
    }

    const quizData = await this.gameService.cachingQuizData(classId);

    await this.redisService.set(`class:${classId}`, JSON.stringify(quizData), 'EX', 604800);

    return quizData;
  }

캐싱된 퀴즈가 있는지 확인하여, 캐싱되어있는 퀴즈가 아닐 경우 퀴즈를 캐싱하고 문제 개수를 반환합니다.

저장된 문제 개수는 gameInfo에 quizMaxNum으로 저장됩니다.

스크린샷

image

💬리뷰 요구사항

7일을 나타내는 정수 값을 상수로 관리해야함 -> utils로 처리해야할 듯

참고 자료

@glaxyt glaxyt added the ✨ Feature 기능 작업 label Nov 20, 2024
@glaxyt glaxyt requested a review from nowChae November 20, 2024 08:21
@glaxyt glaxyt self-assigned this Nov 20, 2024
Copy link
Collaborator

@nowChae nowChae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nowChae nowChae merged commit a0c10aa into develop Nov 20, 2024
@dooohun dooohun deleted the feature/BE/check-quiz-caching branch November 21, 2024 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature 기능 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants