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: Implement Echo Command #2863

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1475,3 +1475,11 @@ func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) (Result[K

return handleKeyWithMemberAndScoreResponse(result)
}

func (client *baseClient) Echo(message string) (Result[string], error) {
result, err := client.executeCommand(C.Echo, []string{message})
if err != nil {
return CreateNilStringResult(), err
}
return handleStringResponse(result)
}
19 changes: 19 additions & 0 deletions go/api/connection_management_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ type ConnectionManagementCommands interface {
//
// [valkey.io]: https://valkey.io/commands/ping/
PingWithMessage(message string) (string, error)

// Echo the provided message back.
// The command will be routed a random node.
//
// Parameters:
// message - The provided message.
//
// Return value:
// The provided message
//
// For example:
// result, err := client.Echo("Hello World")
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: Hello World
//
// [valkey.io]: https://valkey.io/commands/echo/
Echo(message string) (Result[string], error)
}
11 changes: 11 additions & 0 deletions go/integTest/shared_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4456,3 +4456,14 @@ func (suite *GlideTestSuite) TestZRem() {
assert.IsType(suite.T(), &api.RequestError{}, err)
})
}

func (suite *GlideTestSuite) TestEcho() {
suite.runWithDefaultClients(func(client api.BaseClient) {
// Test 1: Check if Echo command return the message
value := "Hello world"
t := suite.T()
resultEcho, err := client.Echo(value)
assert.Nil(t, err)
assert.Equal(t, value, resultEcho.Value())
})
}
Loading