tune default redis opts, add tls config support

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2023-02-01 01:48:47 +03:00
parent 755d601c94
commit ede2cf695c

View File

@ -263,10 +263,16 @@ func (r *rkv) configure() error {
if r.opts.Context != nil { if r.opts.Context != nil {
if c, ok := r.opts.Context.Value(configKey{}).(*redis.Options); ok { if c, ok := r.opts.Context.Value(configKey{}).(*redis.Options); ok {
redisOptions = c redisOptions = c
if r.opts.TLSConfig != nil {
redisOptions.TLSConfig = r.opts.TLSConfig
}
} }
if c, ok := r.opts.Context.Value(clusterConfigKey{}).(*redis.ClusterOptions); ok { if c, ok := r.opts.Context.Value(clusterConfigKey{}).(*redis.ClusterOptions); ok {
redisClusterOptions = c redisClusterOptions = c
if r.opts.TLSConfig != nil {
redisClusterOptions.TLSConfig = r.opts.TLSConfig
}
} }
} }
@ -282,10 +288,31 @@ func (r *rkv) configure() error {
Addr: nodes[0], Addr: nodes[0],
Password: "", // no password set Password: "", // no password set
DB: 0, // use default DB DB: 0, // use default DB
MaxRetries: 2,
MaxRetryBackoff: 256 * time.Millisecond,
DialTimeout: 1 * time.Second,
ReadTimeout: 1 * time.Second,
WriteTimeout: 1 * time.Second,
PoolTimeout: 1 * time.Second,
IdleTimeout: 20 * time.Second,
MinIdleConns: 10,
TLSConfig: r.opts.TLSConfig,
} }
} }
} else if redisOptions == nil && redisClusterOptions == nil && len(nodes) > 1 { } else if redisOptions == nil && redisClusterOptions == nil && len(nodes) > 1 {
redisClusterOptions = &redis.ClusterOptions{Addrs: nodes} redisClusterOptions = &redis.ClusterOptions{
Addrs: nodes,
Password: "", // no password set
MaxRetries: 2,
MaxRetryBackoff: 256 * time.Millisecond,
DialTimeout: 1 * time.Second,
ReadTimeout: 1 * time.Second,
WriteTimeout: 1 * time.Second,
PoolTimeout: 1 * time.Second,
IdleTimeout: 20 * time.Second,
MinIdleConns: 10,
TLSConfig: r.opts.TLSConfig,
}
} }
if redisOptions != nil { if redisOptions != nil {