@@ -154,6 +154,9 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
154154 SentinelUsername : o .SentinelUsername ,
155155 SentinelPassword : o .SentinelPassword ,
156156
157+ RouteByLatency : o .RouteByLatency ,
158+ RouteRandomly : o .RouteRandomly ,
159+
157160 MaxRetries : o .MaxRetries ,
158161 MinRetryBackoff : o .MinRetryBackoff ,
159162 MaxRetryBackoff : o .MaxRetryBackoff ,
@@ -256,14 +259,22 @@ var (
256259// NewUniversalClient returns a new multi client. The type of the returned client depends
257260// on the following conditions:
258261//
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.
262269func 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 != "" :
264274 return NewFailoverClient (opts .Failover ())
265- } else if len (opts .Addrs ) > 1 || opts .IsClusterMode {
275+ case len (opts .Addrs ) > 1 || opts .IsClusterMode :
266276 return NewClusterClient (opts .Cluster ())
277+ default :
278+ return NewClient (opts .Simple ())
267279 }
268- return NewClient (opts .Simple ())
269280}
0 commit comments