Closed savi2w closed 1 month ago
There is a PING command that responds with PONG.
Not sure about valkey documentation but here is redis version
You can do PING with valkey-go by:
package main
import (
"context"
"github.com/valkey-io/valkey-go"
)
func main() {
client, err := valkey.NewClient(valkey.ClientOption{InitAddress: []string{"127.0.0.1:6379"}})
if err != nil {
panic(err)
}
err = client.Do(context.Background(), client.B().Ping().Build()).Error()
}
However, you usually don't need to do that. If the err
return by valkey.NewClient
is nil, the server is guaranteed to be alive.
You can do PING with valkey-go by:
package main import ( "context" "github.com/valkey-io/valkey-go" ) func main() { client, err := valkey.NewClient(valkey.ClientOption{InitAddress: []string{"127.0.0.1:6379"}}) if err != nil { panic(err) } err = client.Do(context.Background(), client.B().Ping().Build()).Error() }
However, you usually don't need to do that. If the
err
return byvalkey.NewClient
is nil, the server is guaranteed to be alive.
Didn't know the Newclient already do that, thanks!
How can I ping a Valkey server just to know if he is alive and healthy? I feel functions like that are extremely useful when you're dealing with microservices and a lot of DBs (especially at the microservice startup)
I know I can set a dumb key or something like, the point here is just to making sure I ain't missing anything