From 3937fc0f35a1916ed62c604d2487b23cf8255b56 Mon Sep 17 00:00:00 2001 From: zhangzhiyan Date: Wed, 7 Aug 2024 10:31:10 +0800 Subject: [PATCH] Feature: two config way both work --- exporter/redis.go | 13 +++++-------- main.go | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/exporter/redis.go b/exporter/redis.go index 3d9be768..8b1ee1dc 100644 --- a/exporter/redis.go +++ b/exporter/redis.go @@ -24,15 +24,12 @@ func (e *Exporter) configureOptions(uri string) ([]redis.DialOption, error) { redis.DialUseTLS(strings.HasPrefix(e.redisAddr, "rediss://")), } - if e.options.User != "" { - options = append(options, redis.DialUsername(e.options.User)) - } - - if e.options.Password != "" { + if e.options.Password != "" && e.options.PasswordMap[uri] != "" { + options = append(options, redis.DialPassword(e.options.PasswordMap[uri])) + } else if e.options.Password != "" && e.options.User != "" { options = append(options, redis.DialPassword(e.options.Password)) - } - - if e.options.PasswordMap[uri] != "" { + options = append(options, redis.DialUsername(e.options.User)) + } else if e.options.PasswordMap[uri] != "" { options = append(options, redis.DialPassword(e.options.PasswordMap[uri])) } diff --git a/main.go b/main.go index 90215d56..a64578c3 100644 --- a/main.go +++ b/main.go @@ -133,7 +133,7 @@ func main() { } passwordMap := make(map[string]string) - if *redisPwd == "" && *redisPwdFile != "" { + if *redisPwdFile != "" { passwordMap, err = exporter.LoadPwdFile(*redisPwdFile) if err != nil { log.Fatalf("Error loading redis passwords from file %s, err: %s", *redisPwdFile, err)