Search code examples
goredisclientgo-redis

golang redis client connection status


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.


Solution

  • 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)
    }