feat: allow more control on redis client configuration
Cadoles/bouncer/pipeline/head This commit was not built Details

This commit is contained in:
wpetit 2024-10-11 14:17:45 +02:00
parent 69501f6302
commit 11375e546f
2 changed files with 34 additions and 18 deletions

View File

@ -15,8 +15,16 @@ type RedisConfig struct {
WriteTimeout InterpolatedDuration `yaml:"writeTimeout"`
DialTimeout InterpolatedDuration `yaml:"dialTimeout"`
LockMaxRetries InterpolatedInt `yaml:"lockMaxRetries"`
RouteByLatency InterpolatedBool `yaml:"routeByLatency"`
ContextTimeoutEnabled InterpolatedBool `yaml:"contextTimeoutEnabled"`
MaxRetries InterpolatedInt `yaml:"maxRetries"`
PingInterval InterpolatedDuration `yaml:"pingInterval"`
PoolSize InterpolatedInt `yaml:"poolSize"`
PoolTimeout InterpolatedDuration `yaml:"poolTimeout"`
MinIdleConns InterpolatedInt `yaml:"minIdleConns"`
MaxIdleConns InterpolatedInt `yaml:"maxIdleConns"`
ConnMaxIdleTime InterpolatedDuration `yaml:"connMaxIdleTime"`
ConnMaxLifetime InterpolatedDuration `yaml:"connMaxLifeTime"`
}
func NewDefaultRedisConfig() RedisConfig {
@ -29,5 +37,7 @@ func NewDefaultRedisConfig() RedisConfig {
LockMaxRetries: 10,
MaxRetries: 3,
PingInterval: InterpolatedDuration(30 * time.Second),
ContextTimeoutEnabled: true,
RouteByLatency: true,
}
}

View File

@ -38,9 +38,15 @@ func newRedisClient(conf config.RedisConfig) redis.UniversalClient {
ReadTimeout: time.Duration(conf.ReadTimeout),
WriteTimeout: time.Duration(conf.WriteTimeout),
DialTimeout: time.Duration(conf.DialTimeout),
RouteByLatency: true,
ContextTimeoutEnabled: true,
RouteByLatency: bool(conf.RouteByLatency),
ContextTimeoutEnabled: bool(conf.ContextTimeoutEnabled),
MaxRetries: int(conf.MaxRetries),
PoolSize: int(conf.PoolSize),
PoolTimeout: time.Duration(conf.PoolTimeout),
MinIdleConns: int(conf.MinIdleConns),
MaxIdleConns: int(conf.MaxIdleConns),
ConnMaxIdleTime: time.Duration(conf.ConnMaxIdleTime),
ConnMaxLifetime: time.Duration(conf.ConnMaxLifetime),
})
go func() {