From 02f7ced0bd2ecb12557b36ba7eaf32e92c866c6a Mon Sep 17 00:00:00 2001 From: Vinicius Vasconcelos Date: Mon, 18 Sep 2023 16:28:51 -0300 Subject: [PATCH] feat: expose new redis config --- configs/service.yaml | 1 + internal/app/server/open_saves_test.go | 1 + internal/pkg/cache/redis/redis.go | 3 ++- internal/pkg/config/loader.go | 1 + internal/pkg/config/model.go | 2 ++ 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/configs/service.yaml b/configs/service.yaml index 482b012..2ff5835 100644 --- a/configs/service.yaml +++ b/configs/service.yaml @@ -9,6 +9,7 @@ redis_address: "localhost:6379" redis_max_idle: 500 redis_pool_size: 10000 redis_idle_timeout: 0 +redis_max_conn_age: 0 redis_max_retries: 3 redis_min_retry_backoff: "8ms" redis_max_retry_backoff: "512ms" diff --git a/internal/app/server/open_saves_test.go b/internal/app/server/open_saves_test.go index 4876888..77862b0 100644 --- a/internal/app/server/open_saves_test.go +++ b/internal/app/server/open_saves_test.go @@ -170,6 +170,7 @@ func getOpenSavesServer(ctx context.Context, t *testing.T, cloud string) (*openS Address: r.Addr(), PoolSize: 10000, IdleTimeout: 0, + MaxConnAge: 0, }, } impl, err := newOpenSavesServer(ctx, cfg) diff --git a/internal/pkg/cache/redis/redis.go b/internal/pkg/cache/redis/redis.go index add8098..4905550 100644 --- a/internal/pkg/cache/redis/redis.go +++ b/internal/pkg/cache/redis/redis.go @@ -37,13 +37,14 @@ func NewRedis(address string) *Redis { return NewRedisWithConfig(cfg) } -// NewRedis creates a new Redis instance. +// NewRedisWithConfig creates a new Redis instance with configurable options. func NewRedisWithConfig(cfg *config.RedisConfig) *Redis { o := &redis.Options{ Addr: cfg.Address, MinIdleConns: cfg.MinIdleConns, PoolSize: cfg.PoolSize, IdleTimeout: cfg.IdleTimeout, + MaxConnAge: cfg.MaxConnAge, } c := redis.NewClient(o) diff --git a/internal/pkg/config/loader.go b/internal/pkg/config/loader.go index b61ea7e..bf69601 100644 --- a/internal/pkg/config/loader.go +++ b/internal/pkg/config/loader.go @@ -122,6 +122,7 @@ func Load(path string) (*ServiceConfig, error) { MaxRetries: viper.GetInt(RedisMaxRetries), MinRetyBackoff: viper.GetDuration(RedisMinRetryBackoff), MaxRetryBackoff: viper.GetDuration(RedisMaxRetryBackoff), + MaxConnAge: viper.GetDuration(RedisMaxConnAge), MinIdleConns: viper.GetInt(RedisMinIdleConns), PoolSize: viper.GetInt(RedisPoolSize), IdleTimeout: time.Duration(viper.GetUint(RedisIdleTimeout)) * time.Second, diff --git a/internal/pkg/config/model.go b/internal/pkg/config/model.go index 34819bc..20b5e05 100644 --- a/internal/pkg/config/model.go +++ b/internal/pkg/config/model.go @@ -30,6 +30,7 @@ const ( RedisMinIdleConns = "redis_min_idle_conns" RedisPoolSize = "redis_pool_size" RedisIdleTimeout = "redis_idle_timeout" + RedisMaxConnAge = "redis_max_conn_age" RedisMaxRetries = "redis_max_retries" RedisMinRetryBackoff = "redis_min_retry_backoff" RedisMaxRetryBackoff = "redis_max_retry_backoff" @@ -93,6 +94,7 @@ type RedisConfig struct { MinIdleConns int PoolSize int IdleTimeout time.Duration + MaxConnAge time.Duration } // BlobConfig has Open Saves blob related configurations.