Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Ping function #14

Open
savi2w opened this issue Sep 26, 2024 · 2 comments
Open

[Question] Ping function #14

savi2w opened this issue Sep 26, 2024 · 2 comments

Comments

@savi2w
Copy link

savi2w commented Sep 26, 2024

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

@gotama
Copy link

gotama commented Sep 26, 2024

There is a PING command that responds with PONG.

Not sure about valkey documentation but here is redis version

https://redis.io/docs/latest/commands/ping/

@rueian
Copy link
Collaborator

rueian commented Sep 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants