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

Go: Implementing PING command #2264

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

MikeMwita
Copy link
Collaborator

  • Implemented PING command

@MikeMwita MikeMwita requested a review from a team as a code owner September 10, 2024 20:25
@MikeMwita MikeMwita self-assigned this Sep 10, 2024
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cluster client should have ping with 2 optional arguments - message and route

async def ping(
self, message: Optional[TEncodable] = None, route: Optional[Route] = None
) -> bytes:
"""
Ping the server.

go/api/base_client.go Outdated Show resolved Hide resolved

resultChannel := make(chan payload)
resultChannelPtr := uintptr(unsafe.Pointer(&resultChannel))

// If there are no arguments, pass nil for cArgs and argLengths
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you check for null? Just to confirm that we're not dereferencing it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am checking for null in the executeCommand function, If there are no arguments ( len(cArgs) is 0), I don't dereference the pointers (cArgsPtr and argLengthsPtr ). So they remain nil.

@asafpamzn asafpamzn added the go golang wrapper label Sep 15, 2024
@MikeMwita MikeMwita linked an issue Sep 15, 2024 that may be closed by this pull request
2 tasks

// Ping sends the PING command to the server.
//
// If no argument is provided, returns "PONG". If a message is provided, returns the message.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have two separate implementations of Ping in this case. Ping() with no arguments and PingMessage(message key). I think that would be cleaner.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping()
ping(str)

and for cluster client

ping()
ping(str)
ping(route)
ping(str, route)

// result, err := client.Ping("Hello")
//
//[valkey.io]: https://valkey.io/commands/ping/
Ping(message string) (string, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping command is not part of the StringCommands group. Please add a separate interface for ConnectionManagement commands.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if err != nil {
return "", err
}
return handleStringOrNullResponse(result), nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping command won't return Null response https://valkey.io/commands/ping/.

@@ -213,3 +227,18 @@ func (client *baseClient) GetDel(key string) (string, error) {

return handleStringOrNullResponseWithFree(result), nil
}

func (client *baseClient) Ping(message string) (string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest having separate Methods: Ping & PingWithMessage as in Java impl

@avifenesh
Copy link
Collaborator

Something went wrong with the CI, please have a look and fix 🙏

@MikeMwita MikeMwita force-pushed the implement-ping-command branch 6 times, most recently from 00a14bc to 8e050d1 Compare October 9, 2024 13:02
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to implement a cluster client as a next task, so you can resolve a cases where a command have different implementations and docs in cluster and standalone clients. As less such commands you have at that moment, as easier that would be.

//
// See [valkey.io] for details.
type ConnectionManagementCommands interface {
// Ping sends the PING command to the server.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Ping sends the PING command to the server.
// Pings the server.

Or copy from docs from another client

//
// [valkey.io]: https://valkey.io/commands/lcs/
LCS(key1 string, key2 string) (Result[string], error)
// If key does not exist, returns a [api.NilResult[string]] (api.CreateNilStringResult()).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a part of docstrings or a code comment?

//
//[valkey.io]: https://valkey.io/commands/ping/
Ping() (string, error)
PingWithMessage(message string) (string, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are golang docstrings propagated to all API in such case? If no or you'r not sure - please duplicate docs for PingWithMessage.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check it with a doc generator.

@MikeMwita MikeMwita merged commit ff97ca5 into valkey-io:main Oct 9, 2024
13 checks passed
// If an argument is provided, returns the argument.
//
// For example:
// result, err := client.Ping("Hello")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ping method doesn't receive an argument here.

// If no argument is provided, returns "PONG".
//
// Return value:
// If no argument is provided, returns "PONG".
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to not provide an argument in this method?

@@ -512,3 +512,31 @@ func (client *baseClient) RPush(key string, elements []string) (Result[int64], e

return handleLongResponse(result)
}

func (client *baseClient) Ping() (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return Result[string] from all the methods to keep it consistent and pass the nil string info if an error has occurred. Can you please address this in another PR?

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

Successfully merging this pull request may close these issues.

GO: implement PING command
7 participants