Add FailoverClusterClient support

This commit is contained in:
Alexander Menshchikov 2023-11-10 10:45:04 +03:00
parent 21bd40a47e
commit a486bd90f4
No known key found for this signature in database
GPG Key ID: 5B8140D37109B8D1
1 changed files with 10 additions and 3 deletions

View File

@ -136,6 +136,9 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
SentinelUsername: o.SentinelUsername,
SentinelPassword: o.SentinelPassword,
RouteByLatency: o.RouteByLatency,
RouteRandomly: o.RouteRandomly,
MaxRetries: o.MaxRetries,
MinRetryBackoff: o.MinRetryBackoff,
MaxRetryBackoff: o.MaxRetryBackoff,
@ -234,10 +237,14 @@ var (
// 2. if the number of Addrs is two or more, a ClusterClient is returned.
// 3. Otherwise, a single-node Client is returned.
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
if opts.MasterName != "" {
switch {
case opts.MasterName != "" && (opts.RouteByLatency || opts.RouteRandomly):
return NewFailoverClusterClient(opts.Failover())
case opts.MasterName != "":
return NewFailoverClient(opts.Failover())
} else if len(opts.Addrs) > 1 {
case len(opts.Addrs) > 1:
return NewClusterClient(opts.Cluster())
default:
return NewClient(opts.Simple())
}
return NewClient(opts.Simple())
}