diff --git a/internal/config/config.go b/internal/config/config.go index 7763e83e2..4730704ef 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,6 +17,10 @@ type Config struct { Retention RetentionConfig `yaml:"retention"` } +func (c *Config) Init() { + c.Redis.Port = 6380 +} + // Validate checks constraints in the supplied configuration and returns an error if they are violated. func (c *Config) Validate() error { if err := c.Database.Validate(); err != nil { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 3d1083dc2..89ca9b60b 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -31,6 +31,7 @@ redis: input: miniConf, output: func() *Config { c := &Config{} + c.Init() _ = defaults.Set(c) c.Database.Host = "192.0.2.1" diff --git a/pkg/config/config.go b/pkg/config/config.go index 2a4211d6e..700cf9ed7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -11,6 +11,10 @@ import ( "os" ) +type Initer interface { + Init() +} + type Validator interface { Validate() error } @@ -28,6 +32,10 @@ func FromYAMLFile[T any, P interface { c := P(new(T)) + if initer, ok := any(c).(Initer); ok { + initer.Init() + } + if err := defaults.Set(c); err != nil { return nil, errors.Wrap(err, "can't set config defaults") } diff --git a/pkg/redis/client.go b/pkg/redis/client.go index 057e8f1a4..2cb94015c 100644 --- a/pkg/redis/client.go +++ b/pkg/redis/client.go @@ -99,6 +99,10 @@ func NewClientFromConfig(c *Config, logger *logging.Logger) (*Client, error) { options.Network = "unix" options.Addr = c.Host } else { + port := c.Port + if port == 0 { + port = 6379 + } options.Network = "tcp" options.Addr = utils.JoinHostPort(c.Host, c.Port) } diff --git a/pkg/redis/config.go b/pkg/redis/config.go index 40ce11429..27735a4bc 100644 --- a/pkg/redis/config.go +++ b/pkg/redis/config.go @@ -8,7 +8,7 @@ import ( // Config defines Config client configuration. type Config struct { Host string `yaml:"host"` - Port int `yaml:"port" default:"6380"` + Port int `yaml:"port"` Password string `yaml:"password"` TlsOptions config.TLS `yaml:",inline"` Options Options `yaml:"options"`