From ede2cf695ce57f40e0f573702062d2d7cb251bd7 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 1 Feb 2023 01:48:47 +0300 Subject: [PATCH] tune default redis opts, add tls config support Signed-off-by: Vasiliy Tolstov --- redis.go | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/redis.go b/redis.go index 01cc2e6..1b5a93c 100755 --- a/redis.go +++ b/redis.go @@ -263,10 +263,16 @@ func (r *rkv) configure() error { if r.opts.Context != nil { if c, ok := r.opts.Context.Value(configKey{}).(*redis.Options); ok { redisOptions = c + if r.opts.TLSConfig != nil { + redisOptions.TLSConfig = r.opts.TLSConfig + } } if c, ok := r.opts.Context.Value(clusterConfigKey{}).(*redis.ClusterOptions); ok { redisClusterOptions = c + if r.opts.TLSConfig != nil { + redisClusterOptions.TLSConfig = r.opts.TLSConfig + } } } @@ -279,13 +285,34 @@ func (r *rkv) configure() error { if err != nil { // Backwards compatibility redisOptions = &redis.Options{ - Addr: nodes[0], - Password: "", // no password set - DB: 0, // use default DB + Addr: nodes[0], + Password: "", // no password set + 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 { - 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 {