mirror of https://github.com/go-redis/redis.git
Add FailoverClusterClient support
This commit is contained in:
parent
21bd40a47e
commit
a486bd90f4
13
universal.go
13
universal.go
|
@ -136,6 +136,9 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
|
||||||
SentinelUsername: o.SentinelUsername,
|
SentinelUsername: o.SentinelUsername,
|
||||||
SentinelPassword: o.SentinelPassword,
|
SentinelPassword: o.SentinelPassword,
|
||||||
|
|
||||||
|
RouteByLatency: o.RouteByLatency,
|
||||||
|
RouteRandomly: o.RouteRandomly,
|
||||||
|
|
||||||
MaxRetries: o.MaxRetries,
|
MaxRetries: o.MaxRetries,
|
||||||
MinRetryBackoff: o.MinRetryBackoff,
|
MinRetryBackoff: o.MinRetryBackoff,
|
||||||
MaxRetryBackoff: o.MaxRetryBackoff,
|
MaxRetryBackoff: o.MaxRetryBackoff,
|
||||||
|
@ -234,10 +237,14 @@ var (
|
||||||
// 2. if the number of Addrs is two or more, a ClusterClient is returned.
|
// 2. if the number of Addrs is two or more, a ClusterClient is returned.
|
||||||
// 3. Otherwise, a single-node Client is returned.
|
// 3. Otherwise, a single-node Client is returned.
|
||||||
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
|
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())
|
return NewFailoverClient(opts.Failover())
|
||||||
} else if len(opts.Addrs) > 1 {
|
case len(opts.Addrs) > 1:
|
||||||
return NewClusterClient(opts.Cluster())
|
return NewClusterClient(opts.Cluster())
|
||||||
}
|
default:
|
||||||
return NewClient(opts.Simple())
|
return NewClient(opts.Simple())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue