Skip to content

๐Ÿ”€ :: [#616] - RedisLimitAdapter ๋ฆฌํŽ™ํ† ๋ง#617

Merged
dolong2 merged 4 commits intodevelopfrom
refac/redis-limit-adapter
May 25, 2025
Merged

๐Ÿ”€ :: [#616] - RedisLimitAdapter ๋ฆฌํŽ™ํ† ๋ง#617
dolong2 merged 4 commits intodevelopfrom
refac/redis-limit-adapter

Conversation

@dolong2
Copy link
Owner

@dolong2 dolong2 commented May 25, 2025

๊ฐœ์š”

  • RedisLimitAdapter ๋ฆฌํŽ™ํ† ๋งํ•ฉ๋‹ˆ๋‹ค.
    • ReidsClient๋ฅผ ๋‚ด๋ถ€์—์„œ ์ƒ์„ฑํ•˜๋„๋ก ์ˆ˜์ •

์ž‘์—…๋‚ด์šฉ

  • RedisClient Bean ์ œ๊ฑฐ
  • RedisLimitAdapter์—์„œ RedisConnectionFactory๋ฅผ ์ฃผ์ž…๋ฐ›๋„๋ก ์ˆ˜์ •
  • init์„ ํ†ตํ•ด์„œ bucketProxy๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๋„๋ก ์ˆ˜์ •
  • RedisLimitAdapterTest ์ถ”๊ฐ€

์ฒดํฌ๋ฆฌ์ŠคํŠธ

ํƒฌํ”Œ๋ฆฟ์™ธ์— ํ•„์š”ํ•œ ํ•ญ๋ชฉ์ด ์žˆ์œผ๋ฉด ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.

  • ๋กœ์ปฌ์—์„œ ๋นŒ๋“œ๊ฐ€ ์„ฑ๊ณตํ•˜๋‚˜์š”?
  • ์ถ”๊ฐ€(์ˆ˜์ •)ํ•œ ์ฝ”๋“œ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๋‚˜์š”?
  • pr ํƒ€์ผ“ ๋ธŒ๋žœ์น˜๊ฐ€ ๋งž๊ฒŒ ์„ค์ •๋˜์–ด ์žˆ๋‚˜์š”?
  • pr์—์„œ ์ž‘์—…ํ•  ๋‚ด์šฉ๋งŒ ์ž‘์—…๋๋‚˜์š”?
  • ๊ธฐ์กด API์™€ ํ˜ธํ™˜๋˜์ง€ ์•Š๋Š” ์‚ฌํ•ญ์ด ์žˆ๋‚˜์š”?

Summary by CodeRabbit

  • ๋ฆฌํŒฉํ„ฐ๋ง

    • Redis ์—ฐ๊ฒฐ ๋ฐฉ์‹์ด ๋ณ€๊ฒฝ๋˜์–ด, Redis ๊ด€๋ จ ์„ค์ • ๋ฐ ์–ด๋Œ‘ํ„ฐ์˜ ์ƒ์„ฑ์ž์™€ ๋‚ด๋ถ€ ๊ตฌํ˜„์ด ๊ฐœ์„ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
  • ํ…Œ์ŠคํŠธ

    • Redis ๊ธฐ๋ฐ˜ ์†๋„ ์ œํ•œ ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ์ƒˆ๋กœ์šด ํ…Œ์ŠคํŠธ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

@dolong2 dolong2 linked an issue May 25, 2025 that may be closed by this pull request
@dolong2 dolong2 self-assigned this May 25, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 25, 2025

Walkthrough

Redis ํด๋ผ์ด์–ธํŠธ์˜ ์ƒ์„ฑ ๋ฐ ์ฃผ์ž… ๋ฐฉ์‹์ด ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ์กด์—๋Š” RedisConfig์—์„œ RedisClient ๋นˆ์„ ์ œ๊ณตํ–ˆ์œผ๋‚˜, ์ด์ œ RedisLimitAdapter๊ฐ€ RedisConnectionFactory๋ฅผ ๋ฐ›์•„ ๋‚ด๋ถ€์ ์œผ๋กœ RedisClient๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, RedisLimitAdapter์— ๋Œ€ํ•œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๊ฐ€ ์ƒˆ๋กœ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Changes

ํŒŒ์ผ/๊ฒฝ๋กœ ์š”์•ฝ ๋ณ€๊ฒฝ ๋‚ด์šฉ ์š”์•ฝ
src/main/kotlin/com/dcd/server/infrastructure/global/config/RedisConfig.kt RedisClient ๊ด€๋ จ import ๋ฐ redisClient() ๋นˆ ๋ฉ”์„œ๋“œ ์‚ญ์ œ
src/main/kotlin/com/dcd/server/infrastructure/global/thirdparty/bucket4j/RedisLimitAdapter.kt ์ƒ์„ฑ์ž ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ RedisClient์—์„œ RedisConnectionFactory๋กœ ๋ณ€๊ฒฝ, ๋‚ด๋ถ€์—์„œ RedisClient ์ƒ์„ฑ ๋ฐฉ์‹์œผ๋กœ ์ˆ˜์ •
src/test/kotlin/com/dcd/server/infrastructure/global/thirdparty/bucket4j/RedisLimitAdapterTest.kt RedisLimitAdapter์— ๋Œ€ํ•œ BehaviorSpec ๊ธฐ๋ฐ˜ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค ์‹ ๊ทœ ์ถ”๊ฐ€

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RedisLimitAdapter
    participant RedisConnectionFactory
    participant RedisClient
    participant Redis

    Client->>RedisLimitAdapter: ์ƒ์„ฑ์ž ํ˜ธ์ถœ (RedisConnectionFactory ์ฃผ์ž…)
    RedisLimitAdapter->>RedisConnectionFactory: host/port ์ •๋ณด ์ถ”์ถœ
    RedisLimitAdapter->>RedisClient: RedisClient ์ƒ์„ฑ
    RedisLimitAdapter->>Redis: Bucket4j ProxyManager ์ดˆ๊ธฐํ™”
    Client->>RedisLimitAdapter: consumer/resolveToken ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ
    RedisLimitAdapter->>Redis: ํ† ํฐ ์†Œ๋น„ ๋ฐ ์ œํ•œ ์ฒดํฌ
Loading

Possibly related PRs

Suggested labels

:two: Priority: ์ค‘, :hammer: Refactor

Poem

๐Ÿ‡
Redis์˜ ๊ธธ์„ ์ƒˆ๋กœ์ด ์—ด์—ˆ๋„ค,
๋นˆ์€ ์‚ฌ๋ผ์ง€๊ณ , ์–ด๋Œ‘ํ„ฐ๊ฐ€ ๋งก์•˜๋„ค.
ํ…Œ์ŠคํŠธ๋„ ์ถ”๊ฐ€ํ•ด ์‹ ๋ขฐ๋ฅผ ๋”ํ•˜๊ณ ,
๊น”๋”ํ•œ ์ฝ”๋“œ์— ํ† ๋ผ๋„ ์ถค์ถ”๋„ค!
๐Ÿฅ•โœจ

โœจ Finishing Touches
  • ๐Ÿ“ Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share
๐Ÿชง Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dolong2 dolong2 added 1๏ธโƒฃ Priority: ์ƒ ์šฐ์„ ์ˆœ์œ„ ์ƒ ๐Ÿ”จ Refactor ์ฝ”๋“œ ๋ฆฌํŒฉํ† ๋ง labels May 25, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

๐Ÿงน Nitpick comments (4)
src/test/kotlin/com/dcd/server/infrastructure/global/thirdparty/bucket4j/RedisLimitAdapterTest.kt (2)

13-15: ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค ์˜์กด์„ฑ ์ฃผ์ž… ๋ฐฉ์‹ ๊ฒ€ํ†  ํ•„์š”

์ƒ์„ฑ์ž ์ฃผ์ž…์„ ํ†ตํ•ด RedisLimitAdapter๋ฅผ ๋ฐ›๊ณ  ์žˆ๋Š”๋ฐ, ํ…Œ์ŠคํŠธ ๊ฒฉ๋ฆฌ๋ฅผ ์œ„ํ•ด ๊ฐ ํ…Œ์ŠคํŠธ๋งˆ๋‹ค ๋…๋ฆฝ์ ์ธ ์ธ์Šคํ„ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”.


16-29: ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€๋ฅผ ๊ฐœ์„ ํ•˜์„ธ์š”.

ํ˜„์žฌ ํ…Œ์ŠคํŠธ๋Š” ์šฉ๋Ÿ‰ ์ดˆ๊ณผ ์‹œ false ๋ฐ˜ํ™˜๋งŒ ๊ฒ€์ฆํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ถ”๊ฐ€ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋ฅผ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”:

  1. ์šฉ๋Ÿ‰ ๋‚ด์—์„œ ํ† ํฐ ์†Œ๋น„ ์‹œ true ๋ฐ˜ํ™˜ ๊ฒ€์ฆ
  2. ์‹œ๊ฐ„ ๊ฒฝ๊ณผ ํ›„ ํ† ํฐ ์žฌ์ถฉ์ „ ๊ฒ€์ฆ
  3. ๋‹ค๋ฅธ ํ‚ค์— ๋Œ€ํ•œ ๋…๋ฆฝ์ ์ธ ํ† ํฐ ๊ด€๋ฆฌ ๊ฒ€์ฆ
given("ํ…Œ์ŠคํŠธํ•  Limit ์–ด๋…ธํ…Œ์ด์…˜์ด ์ฃผ์–ด์ง€๊ณ ") {
    val targetLimitAnnotation = Limit(target = "test")

+   `when`("์šฉ๋Ÿ‰ ๋‚ด์—์„œ ํ† ํฐ์„ ์†Œ๋น„ํ• ๋•Œ") {
+       then("๋ฐ˜ํ™˜๊ฐ’์ด true์—ฌ์•ผํ•จ") {
+           redisLimitAdapter.consumer(targetLimitAnnotation.target, targetLimitAnnotation) shouldBe true
+       }
+   }

    `when`("์–ด๋…ธํ…Œ์ด์…˜์— ์„ค์ •๋œ ํšŸ์ˆ˜ ์ดˆ๊ณผ๋กœ ํ† ํฐ์„ ์†Œ๋น„ํ• ๋•Œ") {
        val capacity = targetLimitAnnotation.capacity
        for (i in 0 until capacity) {
            redisLimitAdapter.consumer(targetLimitAnnotation.target, targetLimitAnnotation)
        }

        then("๋ฐ˜ํ™˜๊ฐ’์ด false์—ฌ์•ผํ•จ") {
            redisLimitAdapter.consumer(targetLimitAnnotation.target, targetLimitAnnotation) shouldBe false
        }
    }
}
src/main/kotlin/com/dcd/server/infrastructure/global/thirdparty/bucket4j/RedisLimitAdapter.kt (2)

21-21: ์ƒ์„ฑ์ž ํŒŒ๋ผ๋ฏธํ„ฐ ๋ช…๋ช… ๊ฐœ์„ 

ํŒŒ๋ผ๋ฏธํ„ฐ๋ช…์ด ์ง€์—ญ ๋ณ€์ˆ˜๋กœ๋งŒ ์‚ฌ์šฉ๋˜๋ฏ€๋กœ ๋” ๋ช…ํ™•ํ•œ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”.

-    redisConnectionFactory: RedisConnectionFactory
+    private val redisConnectionFactory: RedisConnectionFactory

31-31: ์—ฐ๊ฒฐ ๋ฌธ์ž์—ด ๋ณด์•ˆ ๊ฐ•ํ™”

ํ•˜๋“œ์ฝ”๋”ฉ๋œ Redis URI ์Šคํ‚ค๋งˆ ๋Œ€์‹  ๋ณด๋‹ค ์•ˆ์ „ํ•œ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”. ํŠนํžˆ ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์—์„œ ์ธ์ฆ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋” ์œ ์—ฐํ•œ URI ์ƒ์„ฑ ๋ฐฉ์‹:

val redisUri = if (connectionFactory.password != null) {
    "redis://:${connectionFactory.password}@$hostName:$port"
} else {
    "redis://$hostName:$port"
}
val redisClient = RedisClient.create(redisUri)
๐Ÿ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 31600d5 and 6e6cbc1.

๐Ÿ“’ Files selected for processing (3)
  • src/main/kotlin/com/dcd/server/infrastructure/global/config/RedisConfig.kt (0 hunks)
  • src/main/kotlin/com/dcd/server/infrastructure/global/thirdparty/bucket4j/RedisLimitAdapter.kt (1 hunks)
  • src/test/kotlin/com/dcd/server/infrastructure/global/thirdparty/bucket4j/RedisLimitAdapterTest.kt (1 hunks)
๐Ÿ’ค Files with no reviewable changes (1)
  • src/main/kotlin/com/dcd/server/infrastructure/global/config/RedisConfig.kt
โฐ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test
๐Ÿ”‡ Additional comments (1)
src/main/kotlin/com/dcd/server/infrastructure/global/thirdparty/bucket4j/RedisLimitAdapter.kt (1)

21-21: ์˜์กด์„ฑ ์ฃผ์ž… ๊ฐœ์„ ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.

RedisConnectionFactory๋ฅผ ํ†ตํ•œ ์˜์กด์„ฑ ์ฃผ์ž…์œผ๋กœ ๋ณ€๊ฒฝํ•œ ๊ฒƒ์€ ์ข‹์€ ๊ฐœ์„ ์ž…๋‹ˆ๋‹ค. ์ด๋Š” ๋” ์œ ์—ฐํ•œ Redis ์—ฐ๊ฒฐ ์„ค์ •์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

@dolong2 dolong2 merged commit 18ed796 into develop May 25, 2025
2 checks passed
@dolong2 dolong2 deleted the refac/redis-limit-adapter branch May 25, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

๐Ÿ”จ Refactor ์ฝ”๋“œ ๋ฆฌํŒฉํ† ๋ง 1๏ธโƒฃ Priority: ์ƒ ์šฐ์„ ์ˆœ์œ„ ์ƒ

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RedisLimitAdapter ๋ฆฌํŽ™ํ† ๋ง

1 participant