hellofresh/health-go

how to config the DSN in redis cluster mode

KamJohn opened this issue ยท 3 comments

please tell how to config the DSN in redis cluster mode

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>

got it. thank you for help