@@ -154,6 +154,9 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
154
154
SentinelUsername : o .SentinelUsername ,
155
155
SentinelPassword : o .SentinelPassword ,
156
156
157
+ RouteByLatency : o .RouteByLatency ,
158
+ RouteRandomly : o .RouteRandomly ,
159
+
157
160
MaxRetries : o .MaxRetries ,
158
161
MinRetryBackoff : o .MinRetryBackoff ,
159
162
MaxRetryBackoff : o .MaxRetryBackoff ,
@@ -256,14 +259,22 @@ var (
256
259
// NewUniversalClient returns a new multi client. The type of the returned client depends
257
260
// on the following conditions:
258
261
//
259
- // 1. If the MasterName option is specified, a sentinel-backed FailoverClient is returned.
260
- // 2. if the number of Addrs is two or more, a ClusterClient is returned.
261
- // 3. Otherwise, a single-node Client is returned.
262
+ // 1. If the MasterName option is specified with RouteByLatency, RouteRandomly or IsClusterMode,
263
+ // a FailoverClusterClient is returned.
264
+ // 2. If the MasterName option is specified without RouteByLatency, RouteRandomly or IsClusterMode,
265
+ // a sentinel-backed FailoverClient is returned.
266
+ // 3. If the number of Addrs is two or more, or IsClusterMode option is specified,
267
+ // a ClusterClient is returned.
268
+ // 4. Otherwise, a single-node Client is returned.
262
269
func NewUniversalClient (opts * UniversalOptions ) UniversalClient {
263
- if opts .MasterName != "" {
270
+ switch {
271
+ case opts .MasterName != "" && (opts .RouteByLatency || opts .RouteRandomly || opts .IsClusterMode ):
272
+ return NewFailoverClusterClient (opts .Failover ())
273
+ case opts .MasterName != "" :
264
274
return NewFailoverClient (opts .Failover ())
265
- } else if len (opts .Addrs ) > 1 || opts .IsClusterMode {
275
+ case len (opts .Addrs ) > 1 || opts .IsClusterMode :
266
276
return NewClusterClient (opts .Cluster ())
277
+ default :
278
+ return NewClient (opts .Simple ())
267
279
}
268
- return NewClient (opts .Simple ())
269
280
}
0 commit comments