diff --git a/go/api/base_client.go b/go/api/base_client.go index 6505c8700f..604a67c79f 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -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) +} diff --git a/go/api/connection_management_commands.go b/go/api/connection_management_commands.go index f51f41cf29..59d4c3c372 100644 --- a/go/api/connection_management_commands.go +++ b/go/api/connection_management_commands.go @@ -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) } diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index 5a01b8595b..333be34c72 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -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()) + }) +}