Skip to content

Add parsing of multiple URLs for cluster mode in redis #1923

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

Closed

Conversation

stephaniehingtgen
Copy link
Contributor

@stephaniehingtgen stephaniehingtgen commented Oct 16, 2021

What this PR does
This PR adds a new function, ParseClusterURLs, which takes an array of strings and turns it into the array of addresses used for redis in cluster mode along with configurations passed in.

How it works
It is very similar to the ParseURL function, except for this function loops through an array of URLs. It will get the username and password for the cluster as well as configurations sent in through the query parameters.

Since the connection to the cluster can only have one username and password, if it differs between URLs in the array, the function will fail. Additionally, if the schemes differ, it will fail. I did not implement checks on the query parameters differing. If we want this done, I definitely could do it, but with the defaults and the init function it starts getting a bit uglier to check for all of those. If the query parameters do differ, it will use the last one in the array.

Example of arrays that will succeed:

["redis://localhost:6378", "redis://localhost:6379"]
["rediss://localhost:6378", "rediss://localhost:6379"]
["redis://foo:bar@localhost:6378?read_timeout=1s", "redis://foo:bar@localhost:6379?read_timeout=2s"] // no checks on query parameters

Example of arrays that will fail:

["redis://localhost:6378", "localhost:6379"] // schemes differ
["redis://foo:bar@localhost:6378", "redis://foo@localhost:6379"] // passwords differ
["redis://foo:bar@localhost:6378", "redis://foo:hello@localhost:6379"] // passwords differ
["redis://foo:bar@localhost:6378", "redis://bar:hello@localhost:6379"] // usernames differ

@stephaniehingtgen stephaniehingtgen deleted the cluster-parse-url branch October 16, 2021 04:05
@stephaniehingtgen
Copy link
Contributor Author

closing in favor of #1924

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.

1 participant