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

fix : redis 랭킹 버그 수정 #150

Merged
merged 13 commits into from
Dec 17, 2023
Merged

fix : redis 랭킹 버그 수정 #150

merged 13 commits into from
Dec 17, 2023

Conversation

kshired
Copy link
Member

@kshired kshired commented Nov 27, 2023

Issue Number

close: # N/A

작업 내역

구현 내용 및 작업 했던 내역

  • ranking 버그 수정
  • redis ranking 조회 리팩터링

변경사항

  • 의존성 목록 : N/A

작업 유형

  • 신규 기능 추가
  • 버그 수정
  • 리펙토링
  • 문서 업데이트

PR 특이 사항

PR을 볼 때 주의깊게 봐야하거나 말하고 싶은 점

  • zset().add 로 매번 존재하는건 replace하고, 없어진건 그대로 냅두는 방식으로 구현되어서 있어서 추가전 데이터를 지우고 추가하도록 변경
    • 데이터를 추가하거나 할 때 에러가 발생할 수 있으므로, transaction management를 받도록 수정
  • redis를 통한 ranking 조회 로직을 함수형으로 리팩터링 함

@kshired kshired requested a review from ekzm8523 November 27, 2023 14:42
@kshired kshired temporarily deployed to commit November 27, 2023 14:42 Inactive
@kshired kshired temporarily deployed to commit November 27, 2023 14:49 Inactive
@kshired kshired temporarily deployed to commit November 27, 2023 15:08 Inactive
@kshired kshired temporarily deployed to commit November 30, 2023 06:27 Inactive
@kshired kshired added the bug Something isn't working label Nov 30, 2023
@kshired kshired temporarily deployed to commit December 9, 2023 17:46 Inactive
@kshired kshired temporarily deployed to commit December 9, 2023 18:03 Inactive
Copy link
Member

@ekzm8523 ekzm8523 left a comment

Choose a reason for hiding this comment

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

코멘트 몇개 남겼습니다!

Comment on lines 62 to 67
val rankKey = redisTemplate.opsForZSet().reverseRangeByScore(RANKING, score, score, 0, 1)?.firstOrNull()

if (rankKey != null) {
rank = redisTemplate.opsForZSet().reverseRank(RANKING, rankKey)?.plus(1)
val rank = rankKey?.let {
redisTemplate.opsForZSet().reverseRank(RANKING, rankKey)?.plus(1)
}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val rankKey = redisTemplate.opsForZSet().reverseRangeByScore(RANKING, score, score, 0, 1)?.firstOrNull()
if (rankKey != null) {
rank = redisTemplate.opsForZSet().reverseRank(RANKING, rankKey)?.plus(1)
val rank = rankKey?.let {
redisTemplate.opsForZSet().reverseRank(RANKING, rankKey)?.plus(1)
}
val rankKey = redisTemplate.opsForZSet().reverseRangeByScore(RANKING, score, score, 0, 1)?.first()
val rank = redisTemplate.opsForZSet().reverseRank(RANKING, rankKey!!)?.plus(1)

위에 score가 받아져왔다는 건 무조건 하나 이상의 점수가 레디스에 있다는 거니까 !!를 통해 무조건 존재한다는 걸 코드에 내포하는 건 어떨까요?
�위와 같이 정리하면 코드가 더 깔끔해질 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

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

@ekzm8523 이건 사람마다 의견이 다를 수 있을 것 같아요. 저는 후자인듯?

rank의 score과 key가 확실하게 존재한다는 것을 의미하게 코드 짜기 vs ? 을 사용하여 null 안정성을 확보하면서 코드짜기.

어떻게 생각하시나요

Copy link
Member

Choose a reason for hiding this comment

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

마지막에 변경된 rankKey?.let도 적절해보입니다~ 이렇게 가시져

@kshired kshired temporarily deployed to commit December 10, 2023 12:24 Inactive
@kshired kshired temporarily deployed to commit December 10, 2023 14:47 Inactive
@kshired kshired temporarily deployed to commit December 17, 2023 04:11 Inactive
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@kshired kshired merged commit fd8030e into dev Dec 17, 2023
5 checks passed
@kshired kshired deleted the fix/redis-ranking-bug branch December 17, 2023 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants