added more redis config env vars

This commit is contained in:
Marko Gaćeša 2021-08-11 16:25:50 +02:00
parent fb29636608
commit cf7d30a7f6
2 changed files with 16 additions and 5 deletions

View file

@ -170,6 +170,9 @@ type (
// Redis provides the redis configuration. // Redis provides the redis configuration.
Redis struct { Redis struct {
ConnectionString string `envconfig:"DRONE_REDIS_CONNECTION"` ConnectionString string `envconfig:"DRONE_REDIS_CONNECTION"`
Addr string `envconfig:"DRONE_REDIS_ADDR"`
Password string `envconfig:"DRONE_REDIS_PASSWORD"`
DB int `envconfig:"DRONE_REDIS_DB"`
} }
// Repository provides the repository configuration. // Repository provides the repository configuration.

View file

@ -26,12 +26,20 @@ import (
) )
func New(config config.Config) (srv RedisDB, err error) { func New(config config.Config) (srv RedisDB, err error) {
if config.Redis.ConnectionString == "" { var options *redis.Options
return
}
options, err := redis.ParseURL(config.Redis.ConnectionString) if config.Redis.ConnectionString != "" {
if err != nil { options, err = redis.ParseURL(config.Redis.ConnectionString)
if err != nil {
return
}
} else if config.Redis.Addr != "" {
options = &redis.Options{
Addr: config.Redis.Addr,
Password: config.Redis.Password,
DB: config.Redis.DB,
}
} else {
return return
} }