From afda87532cce7376fc59a7d5b4e3a8b3fcef0694 Mon Sep 17 00:00:00 2001 From: Richard87 Date: Tue, 2 Sep 2025 13:00:16 +0200 Subject: [PATCH] fix: dont override parameters set in redis uri --- pkg/sessions/redis/redis_store.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/sessions/redis/redis_store.go b/pkg/sessions/redis/redis_store.go index 4e846e9b..79f8f7d1 100644 --- a/pkg/sessions/redis/redis_store.go +++ b/pkg/sessions/redis/redis_store.go @@ -109,6 +109,9 @@ func buildSentinelClient(opts options.RedisStoreOptions) (Client, error) { if opts.Username != "" { opt.Username = opts.Username } + if opts.IdleTimeout > 0 { + opt.ConnMaxIdleTime = time.Duration(opts.IdleTimeout) * time.Second + } if err := setupTLSConfig(opts, opt); err != nil { return nil, err @@ -118,10 +121,10 @@ func buildSentinelClient(opts options.RedisStoreOptions) (Client, error) { MasterName: opts.SentinelMasterName, SentinelAddrs: addrs, SentinelPassword: opts.SentinelPassword, - Username: opts.Username, - Password: opts.Password, + Username: opt.Username, + Password: opt.Password, TLSConfig: opt.TLSConfig, - ConnMaxIdleTime: time.Duration(opts.IdleTimeout) * time.Second, + ConnMaxIdleTime: opt.ConnMaxIdleTime, }) return newClient(client), nil } @@ -139,6 +142,9 @@ func buildClusterClient(opts options.RedisStoreOptions) (Client, error) { if opts.Username != "" { opt.Username = opts.Username } + if opts.IdleTimeout > 0 { + opt.ConnMaxIdleTime = time.Duration(opts.IdleTimeout) * time.Second + } if err := setupTLSConfig(opts, opt); err != nil { return nil, err @@ -146,10 +152,10 @@ func buildClusterClient(opts options.RedisStoreOptions) (Client, error) { client := redis.NewClusterClient(&redis.ClusterOptions{ Addrs: addrs, - Username: opts.Username, - Password: opts.Password, + Username: opt.Username, + Password: opt.Password, TLSConfig: opt.TLSConfig, - ConnMaxIdleTime: time.Duration(opts.IdleTimeout) * time.Second, + ConnMaxIdleTime: opt.ConnMaxIdleTime, }) return newClusterClient(client), nil } @@ -168,13 +174,14 @@ func buildStandaloneClient(opts options.RedisStoreOptions) (Client, error) { if opts.Username != "" { opt.Username = opts.Username } + if opts.IdleTimeout > 0 { + opt.ConnMaxIdleTime = time.Duration(opts.IdleTimeout) * time.Second + } if err := setupTLSConfig(opts, opt); err != nil { return nil, err } - opt.ConnMaxIdleTime = time.Duration(opts.IdleTimeout) * time.Second - client := redis.NewClient(opt) return newClient(client), nil }