After creting a new Redis client, is there a way to check the status of the connection?
As a way to ensure that the Sentinel is in a healthy state, a status check after instantiation would be ideal.
Some client libraries offer a Ping()
method that executes Redis' PING
command to check the status of the connection:
redisClient := redis.NewClient(...)
if err := redisClient.Ping(ctx).Err(); err != nil {
log.Fatal(err)
}
If you use go-redis client for connecting to redis then you can try the following to check if redis is connected properly.
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
if pong := client.Ping(ctx); pong.String() != "ping: PONG" {
log.Println("-------------Error connection redis ----------:", pong)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With