hellofresh / health-go

Library to provide basic healthcheck functionality to Go applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to config the DSN in redis cluster mode

KamJohn opened this issue · comments

commented

please tell how to config the DSN in redis cluster mode

commented

with password

Hi @KamJohn 👋

Unfortunately the existing Redis check does not support cluster connection.

However you should be able to create a custom check that achieves this:

	h, _ := health.New(health.WithChecks(health.Config{
		Name:      "redis_cluster",
		Check: func(ctx context.Context) error {
			rdb := redis.NewClusterClient(&redis.ClusterOptions{
				Addrs: []string{":7000", ":7001", ":7002", ":7003", ":7004", ":7005"},
			})
			pong, err := rdb.Ping(ctx).Result()
			if err != nil {
				return fmt.Errorf("redis ping failed: %w", err)
			}

			if pong != "PONG" {
				return fmt.Errorf("unexpected response for redis ping: %q", pong)
			}

			return nil
		}},
	}))

For single instances with authentication, you should be able to pass the credentials in the DSN:

redis://<user>:<password>@<host>:<port>/<db_number>
commented

got it. thank you for help