mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Add ClusterOptions.NewClient hook
Replaces https://github.com/go-redis/redis/pull/1316
This commit is contained in:
11
cluster.go
11
cluster.go
@ -68,6 +68,9 @@ type ClusterOptions struct {
|
|||||||
ReadTimeout time.Duration
|
ReadTimeout time.Duration
|
||||||
WriteTimeout time.Duration
|
WriteTimeout time.Duration
|
||||||
|
|
||||||
|
// NewClient creates a cluster node client with provided name and options.
|
||||||
|
NewClient func(opt *Options) *Client
|
||||||
|
|
||||||
// PoolSize applies per cluster node and not for the whole cluster.
|
// PoolSize applies per cluster node and not for the whole cluster.
|
||||||
PoolSize int
|
PoolSize int
|
||||||
MinIdleConns int
|
MinIdleConns int
|
||||||
@ -77,7 +80,6 @@ type ClusterOptions struct {
|
|||||||
IdleCheckFrequency time.Duration
|
IdleCheckFrequency time.Duration
|
||||||
|
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
Limiter Limiter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opt *ClusterOptions) init() {
|
func (opt *ClusterOptions) init() {
|
||||||
@ -120,6 +122,10 @@ func (opt *ClusterOptions) init() {
|
|||||||
case 0:
|
case 0:
|
||||||
opt.MaxRetryBackoff = 512 * time.Millisecond
|
opt.MaxRetryBackoff = 512 * time.Millisecond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opt.NewClient == nil {
|
||||||
|
opt.NewClient = NewClient
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opt *ClusterOptions) clientOptions() *Options {
|
func (opt *ClusterOptions) clientOptions() *Options {
|
||||||
@ -148,7 +154,6 @@ func (opt *ClusterOptions) clientOptions() *Options {
|
|||||||
IdleCheckFrequency: disableIdleCheck,
|
IdleCheckFrequency: disableIdleCheck,
|
||||||
|
|
||||||
TLSConfig: opt.TLSConfig,
|
TLSConfig: opt.TLSConfig,
|
||||||
Limiter: opt.Limiter,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +171,7 @@ func newClusterNode(clOpt *ClusterOptions, addr string) *clusterNode {
|
|||||||
opt := clOpt.clientOptions()
|
opt := clOpt.clientOptions()
|
||||||
opt.Addr = addr
|
opt.Addr = addr
|
||||||
node := clusterNode{
|
node := clusterNode{
|
||||||
Client: NewClient(opt),
|
Client: clOpt.NewClient(opt),
|
||||||
}
|
}
|
||||||
|
|
||||||
node.latency = math.MaxUint32
|
node.latency = math.MaxUint32
|
||||||
|
Reference in New Issue
Block a user