From d788aab6eb0e37e0343e49cc3d1c0f16c0cdda4a Mon Sep 17 00:00:00 2001 From: eliflores Date: Wed, 19 Oct 2022 14:16:23 +0200 Subject: [PATCH] Change the redis check to accept a DSNs with credentials Closes https://github.com/hellofresh/health-go/issues/81 Co-authored-by: Lucas Medeiros --- checks/redis/check.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/checks/redis/check.go b/checks/redis/check.go index 486c7e3..86bcb2f 100644 --- a/checks/redis/check.go +++ b/checks/redis/check.go @@ -21,13 +21,14 @@ func New(config Config) func(ctx context.Context) error { // support all DSN formats (for backward compatibility) - with and w/out schema and path part: // - redis://localhost:1234/ // - localhost:1234 - redisDSN := strings.TrimPrefix(config.DSN, "redis://") - redisDSN = strings.TrimSuffix(redisDSN, "/") + redisDSN := config.DSN + if !strings.HasPrefix(redisDSN, "redis://") { + redisDSN = fmt.Sprintf("redis://%s", redisDSN) + } + redisOptions, _ := redis.ParseURL(redisDSN) return func(ctx context.Context) error { - rdb := redis.NewClient(&redis.Options{ - Addr: redisDSN, - }) + rdb := redis.NewClient(redisOptions) defer rdb.Close() pong, err := rdb.Ping(ctx).Result()