Skip to content

Comments

feat: 모든 계좌 잔액 합산 조회 redis 적용#120

Open
Yang-Chaeyeon wants to merge 7 commits intomainfrom
feat/#117
Open

feat: 모든 계좌 잔액 합산 조회 redis 적용#120
Yang-Chaeyeon wants to merge 7 commits intomainfrom
feat/#117

Conversation

@Yang-Chaeyeon
Copy link
Collaborator

@Yang-Chaeyeon Yang-Chaeyeon commented Dec 6, 2025

🗞️ 연관된 이슈

🔥 이슈번호

✅ 작업 내용

  • 모든 계좌 잔액 합산 조회 redis 적용

📸 스크린샷 (선택)

체크리스트 ✅

  • 코드가 정상적으로 컴파일되나요?
  • merge할 브랜치의 위치를 확인했나요?
  • 테스트 코드를 작성하셨나요?

기타

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Yang-Chaeyeon, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 사용자 계좌의 총 잔액 조회 기능에 Redis 캐싱을 적용하여 애플리케이션의 성능을 최적화하는 것을 목표로 합니다. 데이터 조회 속도를 향상시키고, 계좌 생성이나 송금과 같은 변경 사항 발생 시 캐시를 적절히 무효화하여 데이터의 최신성을 보장합니다.

Highlights

  • Redis 통합: 사용자 계좌의 총 잔액 조회 성능 향상을 위해 Redis 캐싱을 도입했습니다. 이를 위해 spring-boot-starter-data-redis 의존성을 추가하고 Redis 설정을 구성했습니다.
  • 총 잔액 캐싱 로직 구현: AccountServicegetTotalBalanceByUserId 메서드에 Redis 캐싱 로직을 적용했습니다. 첫 조회 시 DB에서 데이터를 가져와 Redis에 10분간 캐싱하고, 이후 조회 시에는 캐시된 데이터를 사용합니다.
  • 캐시 무효화 전략: 데이터 일관성을 유지하기 위해 계좌 생성(createAccount) 및 해외 송금(execute in RemittanceProcessorService) 발생 시 해당 사용자의 총 잔액 캐시를 무효화하도록 구현했습니다.
  • Redis 설정 추가: application.yml에 Redis 연결 정보(호스트, 포트, 타임아웃)를 추가하고, RedisConfig 클래스를 통해 RedisTemplate을 설정하여 Redis와의 상호작용을 관리합니다.
  • 테스트 코드 추가: Redis 캐싱 및 무효화 동작을 검증하기 위한 AccountServiceCacheTest와 기본적인 Redis 연결 테스트를 위한 RedisTest를 추가했습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이번 PR은 모든 계좌의 잔액 합산 조회 기능에 Redis 캐싱을 적용하여 성능을 개선하는 것을 목표로 하고 있습니다. 캐싱 로직의 도입과 캐시 무효화 구현은 좋은 방향입니다. 다만, 몇 가지 개선점을 제안합니다. RedisTemplate의 사용법을 설정에 맞게 최적화하고, DB 조회 효율성을 높이며, 테스트 코드의 안정성을 확보하는 방향으로 코드를 수정하면 더 완성도 높은 기능이 될 것입니다. 또한, 설정 값과 캐시 키 같은 부분은 상수를 사용하거나 외부 설정으로 분리하여 유지보수성을 높이는 것이 좋습니다. 자세한 내용은 각 파일에 남긴 코멘트를 참고해주세요.

@Yang-Chaeyeon
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 모든 계좌의 잔액 합산 조회 기능에 Redis 캐싱을 적용하여 성능을 개선하는 것을 목표로 하고 있습니다. 전반적으로 캐시 적용 및 무효화 로직의 구현 방향은 좋으나, 몇 가지 중요한 수정이 필요합니다. 특히, 캐시 조회 로직에 치명적인 버그가 있어 캐시가 전혀 동작하지 않는 문제가 있습니다. 또한, 테스트 코드의 견고성을 높이고 설정 값 관리를 개선할 수 있는 부분을 발견하여 관련 의견을 남겼습니다. 자세한 내용은 각 파일의 리뷰 코멘트를 참고해주세요.

@Yang-Chaeyeon
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 모든 계좌의 잔액 합산 조회 기능에 Redis 캐싱을 적용하여 성능을 개선하는 것을 목표로 합니다. 전반적으로 캐시 읽기, 쓰기, 무효화 로직이 잘 구현되었습니다. 특히 계좌 생성 및 해외 송금 시 캐시를 무효화하는 로직이 추가된 점이 좋습니다. 또한, 캐싱 로직을 검증하기 위한 통합 테스트를 추가한 점도 훌륭합니다.

다만, 몇 가지 개선할 점이 보입니다.

  1. AccountService.processTransaction 메서드에서 잔액 변경이 발생함에도 캐시 무효화 로직이 누락되어 데이터 정합성 문제가 발생할 수 있습니다. (critical)
  2. 기존 단위 테스트(AccountServiceTest)가 비활성화되었습니다. 새로운 의존성을 Mocking하여 테스트를 유지하는 것이 좋습니다. (high)
  3. RedisConfig에서 Spring이 관리하는 ObjectMapper를 사용하도록 개선하면 더 일관성 있는 JSON 직렬화를 보장할 수 있습니다. (medium)
  4. AccountService 내 사용되지 않는 ObjectMapper 필드를 제거하여 코드의 명확성을 높일 수 있습니다. (medium)
  5. 캐시 무효화 로직의 완전성을 보장하기 위해, 잔액 변경 트랜잭션 발생 후 캐시가 올바르게 무효화되는지에 대한 테스트 케이스 추가를 고려해야 합니다. (medium)

자세한 내용은 각 파일의 개별 코멘트를 참고해주세요.

import static org.mockito.BDDMockito.willDoNothing;
import static org.mockito.Mockito.*;

@Disabled
Copy link
Contributor

Choose a reason for hiding this comment

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

high

AccountServiceTest 클래스가 @Disabled로 비활성화되었습니다. 캐싱을 위한 통합 테스트가 추가된 것은 좋지만, 기존 단위 테스트를 비활성화하는 것은 좋은 습관이 아닙니다. 단위 테스트는 격리된 로직을 빠르게 검증하는 데 매우 중요합니다. 새로 추가된 RedisTemplate 의존성을 Mocking하여 테스트를 수정하고 다시 활성화하는 것을 권장합니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

시도해봤는데 도저히 안짜져요 추후에 수정하고싶어요...

Comment on lines +73 to +74
@DisplayName("총 잔액 조회 캐싱 및 무효화 전체 시나리오 테스트")
void testTotalBalanceCachingScenario() {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

testTotalBalanceCachingScenario 테스트는 계좌 생성 시 캐시가 무효화되는 것을 잘 검증합니다. 하지만 중요한 시나리오가 빠져있습니다. 바로 입금이나 출금과 같이 잔액을 변경하는 트랜잭션 발생 후 캐시가 무효화되는지에 대한 검증입니다. 이 테스트 케이스를 추가했다면 AccountService.processTransaction에서 캐시 무효화 로직이 누락된 것을 발견할 수 있었을 것입니다. 해당 시나리오에 대한 테스트를 추가하는 것을 고려해주세요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants