-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add ParseURL function for cluster mode #1924
Add ParseURL function for cluster mode #1924
Conversation
… into cluster options
Thanks for the PR and the detailed comment 👍
This is kinda strange, especially since you can connect to a Redis Cluster using a single address. Have you considered using something lke And it is unfortunate that we need to duplicate the code for I would also consider using options API, for example: redis.NewClient(&redis.Options{}, redis.WithDSN("..."))
redis.NewClusterClient(&redis.ClusterOptions{}, redis.WithDSN("...")) Then type configurator interface {
setTimeout(d time.Duration) // redis.WithTimeout(d)
setDB(db int) // redis.WithDB(db)
setValues(query *queryOptions) // unrecognized options specific to the client
}
var _ configurator = (*Options)(nil)
var _ configurator = (*ClusterOptions)(nil)
func WithTimeout(d time.Duration) redis.Option {
return func(c configurator) {
c.setTimeout(d)
}
} This is a much bigger change, but it looks much nicer and more flexible than the exiting one. |
That's a great idea - thanks! I updated the PR to take in one string and be able to read as many
I started looking into this, and it started to seem like it would be a fairly large refactor (as the timeouts are in the base client). Also, the cluster client doesn't have a notion of |
That is okay, but ideally we want to support a single way to connect to a Redis Cluster via
It should just set
|
For what it is worth it, I've "documented" this idea at https://blog.uptrace.dev/posts/go-functional-options-named-args.html#reusing-options-for-different-purposes |
👋 Hey, @vmihailenco, just wanted to follow up and see if you had any further comments on this PR? |
257964a
to
a4e94b7
Compare
@stephaniehingtgen this looks good, but I need some time to experiment with options API first before we merge this PR and make it available for everyone. Sorry for the delay and thanks for your work 👍 |
Excited to see this. One comment regarding the URL format was that I would have expected the list of hosts to be a comma-delimited list in the host part of the URL (like a mongo uri)
This would allow the query parameters to map to connection configuration options. |
Great stuff, any chance that this could get merged? In need of TLS support when connecting to an elisticache redis cluster here.. 😇 |
I'd be happy to make this change! I'd just like to wait to get the go ahead from @vmihailenco before continuing work on this PR. If this PR is going to be used, then I will make that change asap :) |
7d6f91b
to
6fd61e8
Compare
What this PR does
This PR adds a new function,
ParseClusterURL
, which takes a string 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 only allows for theredis
andrediss
schemes and will take one to manyaddr
parameters. It will get the username and password for the cluster as well as configurations sent in through the query parameters.Examples that will succeed:
Examples that will fail: