-
Notifications
You must be signed in to change notification settings - Fork 53
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
Conversation
MikeMwita
commented
Sep 10, 2024
- Implemented PING command
There was a problem hiding this 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
valkey-glide/python/python/glide/async_commands/cluster_commands.py
Lines 174 to 178 in 71d8558
async def ping( | |
self, message: Optional[TEncodable] = None, route: Optional[Route] = None | |
) -> bytes: | |
""" | |
Ping the server. |
go/api/base_client.go
Outdated
|
||
resultChannel := make(chan payload) | ||
resultChannelPtr := uintptr(unsafe.Pointer(&resultChannel)) | ||
|
||
// If there are no arguments, pass nil for cArgs and argLengths |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
f4b1d63
to
cedbffb
Compare
|
||
// Ping sends the PING command to the server. | ||
// | ||
// If no argument is provided, returns "PONG". If a message is provided, returns the message. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
go/api/commands.go
Outdated
// result, err := client.Ping("Hello") | ||
// | ||
//[valkey.io]: https://valkey.io/commands/ping/ | ||
Ping(message string) (string, error) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
go/api/base_client.go
Outdated
if err != nil { | ||
return "", err | ||
} | ||
return handleStringOrNullResponse(result), nil |
There was a problem hiding this comment.
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/.
go/api/base_client.go
Outdated
@@ -213,3 +227,18 @@ func (client *baseClient) GetDel(key string) (string, error) { | |||
|
|||
return handleStringOrNullResponseWithFree(result), nil | |||
} | |||
|
|||
func (client *baseClient) Ping(message string) (string, error) { |
There was a problem hiding this comment.
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
cedbffb
to
5e31c97
Compare
Something went wrong with the CI, please have a look and fix 🙏 |
00a14bc
to
8e050d1
Compare
There was a problem hiding this 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.
go/api/commands.go
Outdated
// | ||
// See [valkey.io] for details. | ||
type ConnectionManagementCommands interface { | ||
// Ping sends the PING command to the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Ping sends the PING command to the server. | |
// Pings the server. |
Or copy from docs from another client
go/api/commands.go
Outdated
// | ||
// [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()). |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
8e050d1
to
338b8e2
Compare
Signed-off-by: MikeMwita <[email protected]>
338b8e2
to
0abbd0d
Compare
// If an argument is provided, returns the argument. | ||
// | ||
// For example: | ||
// result, err := client.Ping("Hello") |
There was a problem hiding this comment.
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". |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?