Skip to content

Commit

Permalink
GO: Implement Echo Command (valkey-io#2863)
Browse files Browse the repository at this point in the history
* Implement Echo Command

Signed-off-by: EdricCua <[email protected]>
Signed-off-by: Edward Liang <[email protected]>
  • Loading branch information
EdricCua authored and edlng committed Jan 20, 2025
1 parent d8ae33d commit 3b7ddc3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
28 changes: 28 additions & 0 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4984,3 +4984,31 @@ func (client *baseClient) ObjectEncoding(key string) (Result[string], error) {
}
return handleStringOrNilResponse(result)
}

// 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/
func (client *baseClient) Echo(message string) (Result[string], error) {
result, err := client.executeCommand(C.Echo, []string{message})
if err != nil {
return CreateNilStringResult(), err
}
return handleStringOrNilResponse(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 @@ -12,4 +12,23 @@ type ConnectionManagementCommands interface {
Ping() (string, error)

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 @@ -5824,3 +5824,14 @@ func (suite *GlideTestSuite) TestRestoreWithOptions() {
assert.Equal(t, value, resultGet_test4.Value())
})
}

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())
})
}

0 comments on commit 3b7ddc3

Please sign in to comment.