how to config the DSN in redis cluster mode
KamJohn opened this issue ยท 3 comments
KamJohn commented
please tell how to config the DSN in redis cluster mode
KamJohn commented
with password
lucasmdrs commented
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>
KamJohn commented
got it. thank you for help