diff --git a/config/redis.go b/config/redis.go index e96c9f2..8d980c4 100644 --- a/config/redis.go +++ b/config/redis.go @@ -6,7 +6,7 @@ type Redis struct { DB int `mapstructure:"db"` Username string `mapstructure:"username"` Password string `mapstructure:"password"` - SslMode string `mapstructure:"ssl-mode"` + SSL bool `mapstructure:"ssl"` Debug bool `mapstructure:"debug"` MaxIdleConnectionsInSecond int `mapstructure:"max-idle-connections-in-second"` MaxOpenConnectionsInSecond int `mapstructure:"max-open-connections-in-second"` diff --git a/env/staging.yaml b/env/staging.yaml index 30dc605..dba27f9 100644 --- a/env/staging.yaml +++ b/env/staging.yaml @@ -36,7 +36,7 @@ redis: username: red-d04c8k49c44c739ga8dg password: ItPzniHv94yr8vY4HTrhCfKoibqBh61T db: 5 - ssl: false + ssl: true max-idle-connections-in-second: 600 max-open-connections-in-second: 600 connection-max-life-time-in-second: 600 diff --git a/internal/accessor/redis/impl.go b/internal/accessor/redis/impl.go index 9915880..36e9e6a 100644 --- a/internal/accessor/redis/impl.go +++ b/internal/accessor/redis/impl.go @@ -1,6 +1,7 @@ package redisaccessor import ( + "crypto/tls" "fmt" "legalgo-BE-go/config" @@ -16,11 +17,19 @@ func Get() *redis.Client { func New(cfg *config.Config) *redis.Client { addr := fmt.Sprintf("%s:%s", cfg.Redis.Host, cfg.Redis.Port) - redisClient = redis.NewClient(&redis.Options{ + options := &redis.Options{ Addr: addr, Password: cfg.Redis.Password, DB: cfg.Redis.DB, - }) + } + if cfg.Redis.Username != "" { + options.Username = cfg.Redis.Username + } + if cfg.Redis.SSL { + options.TLSConfig = &tls.Config{} + } + + redisClient = redis.NewClient(options) return redisClient }