Skip to content

feat: support multi redis addr seperator - #179

Merged
iFurySt merged 2 commits into
AmoyLab:mainfrom
qiankunli:feat/add-redis-addr-seperators
Jul 2, 2025
Merged

iFurySt merged 2 commits into
AmoyLab:mainfrom
qiankunli:feat/add-redis-addr-seperators

Conversation

@qiankunli

@qiankunli qiankunli commented Jul 1, 2025 •

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Add support for parsing multiple Redis address separators by introducing a generic splitting utility and applying it to all Redis clients

New Features:

  • Add SplitByMultipleDelimiters function to utility package

Enhancements:

  • Update Redis storage, session store, and notifier to accept both ";" and "," as address delimiters

Tests:

  • Include unit tests for SplitByMultipleDelimiters function

@sourcery-ai

sourcery-ai Bot commented Jul 1, 2025 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Introduces a regex-based utility for splitting strings by multiple delimiters and refactors all Redis client constructors to leverage this new function, ensuring consistent parsing of multi-address inputs and adding unit tests for verification.

Class diagram for updated Redis client constructors and new utility function

classDiagram
    class RedisStorage {
        +NewRedisStorage(clusterType, addr, masterName, username, password, db)
    }
    class RedisStore {
        +NewRedisStore(logger, cfg)
    }
    class RedisNotifier {
        +NewRedisNotifier(logger, clusterType, addr, masterName, username, password, db, topic, role)
    }
    class utils {
        +FirstNonEmpty(str1, str2 string) string
        +SplitByMultipleDelimiters(s string, delimiters ...string) []string
    }
    RedisStorage ..> utils : uses
    RedisStore ..> utils : uses
    RedisNotifier ..> utils : uses
Loading

Class diagram for new SplitByMultipleDelimiters utility function

classDiagram
    class utils {
        +SplitByMultipleDelimiters(s string, delimiters ...string) []string
    }
Loading

File-Level Changes

Change Details Files
Add SplitByMultipleDelimiters utility in pkg/utils
  • Import regexp and strings packages
  • Implement SplitByMultipleDelimiters using a dynamic regex pattern
  • Add unit tests covering various delimiter scenarios
pkg/utils/str.go
pkg/utils/str_test.go
Refactor Redis client constructors to use new split utility
  • Replace strings.Split(addr, ";") calls with utils.SplitByMultipleDelimiters(addr, ";", ",")
  • Update imports to include pkg/utils and remove unused strings
  • Ensure address lists now support both commas and semicolons
internal/auth/storage/redis.go
internal/mcp/session/redis.go
internal/mcp/storage/notifier/redis.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @qiankunli - I've reviewed your changes - here's some feedback:

  • Consider using strings.FieldsFunc instead of a regex for simpler and more performant splitting on multiple delimiter characters.
  • The current implementation only splits on single characters (not multi‐character strings) and returns empty segments for consecutive or edge delimiters—either filter out empty entries or document this behavior.
  • Rename SplitByMultipleDelimiters to something like SplitByAnyRune or SplitOnChars to clarify it handles individual characters rather than full-string delimiters.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using strings.FieldsFunc instead of a regex for simpler and more performant splitting on multiple delimiter characters.
- The current implementation only splits on single characters (not multi‐character strings) and returns empty segments for consecutive or edge delimiters—either filter out empty entries or document this behavior.
- Rename SplitByMultipleDelimiters to something like SplitByAnyRune or SplitOnChars to clarify it handles individual characters rather than full-string delimiters.

## Individual Comments

### Comment 1
<location> `pkg/utils/str_test.go:8` </location>
<code_context>
+)
+import "github.com/stretchr/testify/assert"
+
+func TestSplitByMultipleDelimiters(t *testing.T) {
+	input := "a,b;c"
+	delimiters := []string{",", ";"}
</code_context>

<issue_to_address>
Missing edge case tests for empty input and consecutive delimiters.

Please add tests for empty input, inputs with only delimiters, consecutive delimiters, and delimiters at the start or end to ensure comprehensive coverage.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread pkg/utils/str_test.go Resolved

@iFurySt iFurySt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thanks

@iFurySt
iFurySt merged commit 07c2176 into AmoyLab:main Jul 2, 2025
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