Skip to content

Commit

Permalink
feat: Pass max_redirects to config (#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetrergeru authored Dec 4, 2024
1 parent 3351b7b commit e742999
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type RedisConfig struct {
ReadTimeout string `yaml:"read_timeout"`
// Write-operation timeout. Default is ReadTimeout seconds.
WriteTimeout string `yaml:"write_timeout"`
// MaxRetries count of redirects.
MaxRedirects int `yaml:"max_redirects"`
// MaxRetries count of retries.
MaxRetries int `yaml:"max_retries"`
// Minimum backoff between retries. Used to calculate exponential backoff. Default value is 0
Expand All @@ -71,6 +73,7 @@ func (config *RedisConfig) GetSettings() redis.DatabaseConfig {
Password: config.Password,
SentinelUsername: config.SentinelUsername,
SentinelPassword: config.SentinelPassword,
MaxRedirects: config.MaxRedirects,
MaxRetries: config.MaxRetries,
MinRetryBackoff: to.Duration(config.MinRetryBackoff),
MaxRetryBackoff: to.Duration(config.MaxRetryBackoff),
Expand Down
6 changes: 6 additions & 0 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ func TestRedisConfig(t *testing.T) {
DialTimeout: "1m",
ReadTimeout: "1m",
WriteTimeout: "1m",
MinRetryBackoff: "10s",
MaxRetryBackoff: "20s",
MaxRetries: 3,
MaxRedirects: 4,
ReadOnly: true,
RouteByLatency: true,
RouteRandomly: true,
Expand All @@ -49,7 +52,10 @@ func TestRedisConfig(t *testing.T) {
DialTimeout: time.Minute,
ReadTimeout: time.Minute,
WriteTimeout: time.Minute,
MinRetryBackoff: time.Second * 10,
MaxRetryBackoff: time.Second * 20,
MaxRetries: 3,
MaxRedirects: 4,
ReadOnly: true,
RouteByLatency: true,
RouteRandomly: true,
Expand Down
1 change: 1 addition & 0 deletions database/redis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type DatabaseConfig struct {
ReadTimeout time.Duration
WriteTimeout time.Duration

MaxRedirects int
MaxRetries int
MinRetryBackoff time.Duration
MaxRetryBackoff time.Duration
Expand Down
1 change: 1 addition & 0 deletions database/redis/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func NewDatabase(logger moira.Logger, config DatabaseConfig, nh NotificationHist
ReadTimeout: config.ReadTimeout,
WriteTimeout: config.WriteTimeout,

MaxRedirects: config.MaxRedirects,
MaxRetries: config.MaxRetries,
MinRetryBackoff: config.MinRetryBackoff,
MaxRetryBackoff: config.MaxRetryBackoff,
Expand Down
2 changes: 0 additions & 2 deletions local/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
redis:
addrs: "redis:6379"
metrics_ttl: 3h
min_retry_backoff: 1s
max_retry_backoff: 10s
telemetry:
graphite:
enabled: true
Expand Down

0 comments on commit e742999

Please sign in to comment.