Skip to content

Commit

Permalink
Change the redis check to accept a DSNs with credentials (#83)
Browse files Browse the repository at this point in the history
Closes #81

Co-authored-by: Lucas Medeiros <[email protected]>
  • Loading branch information
Eli Flores and lucasmdrs authored Oct 19, 2022
1 parent a1fcc22 commit 16d80ba
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions checks/redis/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 16d80ba

Please sign in to comment.