Skip to content

Commit b0ed509

Browse files
committed
Add FailoverClusterClient support
1 parent a402c55 commit b0ed509

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

universal.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
143143
SentinelUsername: o.SentinelUsername,
144144
SentinelPassword: o.SentinelPassword,
145145

146+
RouteByLatency: o.RouteByLatency,
147+
RouteRandomly: o.RouteRandomly,
148+
146149
MaxRetries: o.MaxRetries,
147150
MinRetryBackoff: o.MinRetryBackoff,
148151
MaxRetryBackoff: o.MaxRetryBackoff,
@@ -247,10 +250,14 @@ var (
247250
// 2. if the number of Addrs is two or more, a ClusterClient is returned.
248251
// 3. Otherwise, a single-node Client is returned.
249252
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
250-
if opts.MasterName != "" {
253+
switch {
254+
case opts.MasterName != "" && (opts.RouteByLatency || opts.RouteRandomly):
255+
return NewFailoverClusterClient(opts.Failover())
256+
case opts.MasterName != "":
251257
return NewFailoverClient(opts.Failover())
252-
} else if len(opts.Addrs) > 1 || opts.IsClusterMode {
258+
case len(opts.Addrs) > 1 || opts.IsClusterMode:
253259
return NewClusterClient(opts.Cluster())
260+
default:
261+
return NewClient(opts.Simple())
254262
}
255-
return NewClient(opts.Simple())
256263
}

0 commit comments

Comments
 (0)