-
Notifications
You must be signed in to change notification settings - Fork 0
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
[BG-343]: 채팅 커서 조회 redis cache 구현 (12h / 6h) #78
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194bf57
to
761ad50
Compare
inmonim
reviewed
Aug 12, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Dltmd202
requested changes
Aug 12, 2024
infra/src/main/kotlin/com/backgu/amaker/application/chat/service/ChatUserCacheFacadeService.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Dltmd202
approved these changes
Aug 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
채팅 기능 캐시를 구현하였다
처음 구현해서 생각보다 오래 걸렸다
How
레디스 구조
채팅을 sorted set 에 저장하는 형태로 만들고
score 를 채팅 id 로 설정하였다
이때 유저의 정보는 쉽게 바뀔수 있기 때문에
채팅에는 유저 id 만 저장하고
유저 상세 정보는 hash table 에 저장하였다
또한 특정 채팅방에 속한 유저를 한번에 조회하기 위해
chatroomId를 키로 하는 hash table에
유저 id를 리스트로 저장하였다
저장 형태
채팅과 이벤트를 생성할 때 레디스 캐시에 저장되게 만들었다
현재는 채팅방마다 200개가 저장될 수 있게 하였다
조회 형태
이전 채팅 조회
먼저 레디스를 조회하고 부족한 채팅수 만큼 db를 조회하게 함
이후 채팅 조회
조회 하려는 커서가 현재 레디스의 score 에 포함이 되는지 확인한다
만약 포함이 되면 레디스를 통해서 조회를 하고
포함되지 않으면 db를 호출하여 조회를 한다
Result
Link
BG-343