@@ -143,6 +143,9 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
143
143
SentinelUsername : o .SentinelUsername ,
144
144
SentinelPassword : o .SentinelPassword ,
145
145
146
+ RouteByLatency : o .RouteByLatency ,
147
+ RouteRandomly : o .RouteRandomly ,
148
+
146
149
MaxRetries : o .MaxRetries ,
147
150
MinRetryBackoff : o .MinRetryBackoff ,
148
151
MaxRetryBackoff : o .MaxRetryBackoff ,
@@ -247,10 +250,14 @@ var (
247
250
// 2. if the number of Addrs is two or more, a ClusterClient is returned.
248
251
// 3. Otherwise, a single-node Client is returned.
249
252
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 != "" :
251
257
return NewFailoverClient (opts .Failover ())
252
- } else if len (opts .Addrs ) > 1 || opts .IsClusterMode {
258
+ case len (opts .Addrs ) > 1 || opts .IsClusterMode :
253
259
return NewClusterClient (opts .Cluster ())
260
+ default :
261
+ return NewClient (opts .Simple ())
254
262
}
255
- return NewClient (opts .Simple ())
256
263
}
0 commit comments