From d08f61ce04081efadd7fcfadfe1bf3cedfa06b5c Mon Sep 17 00:00:00 2001 From: EdricCua Date: Tue, 24 Dec 2024 08:43:44 +0000 Subject: [PATCH 1/7] Implement Echo Command Signed-off-by: EdricCua --- go/api/base_client.go | 8 ++++++++ go/api/commands.go | 17 +++++++++++++++++ go/integTest/shared_commands_test.go | 10 ++++++++++ 3 files changed, 35 insertions(+) diff --git a/go/api/base_client.go b/go/api/base_client.go index 7e1f5722a1..c550930678 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -1348,3 +1348,11 @@ func (client *baseClient) ZPopMaxWithCount(key string, count int64) (map[Result[ } return handleStringDoubleMapResponse(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 handleStringOrNullResponse(result) +} diff --git a/go/api/commands.go b/go/api/commands.go index 8f62892024..7dcc6b023c 100644 --- a/go/api/commands.go +++ b/go/api/commands.go @@ -782,4 +782,21 @@ type ConnectionManagementCommands interface { // // [valkey.io]: https://valkey.io/commands/ping/ PingWithMessage(message string) (string, error) + + // Echo the provided message back. + // Parameters: + // string 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 c812f93bcc..a421bdd881 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -4039,3 +4039,13 @@ func (suite *GlideTestSuite) TestZPopMax() { 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" + resultEcho, err := client.Echo(value) + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), value, resultEcho.Value()) + }) +} From 2ac4523fe5714d35e32304c4d6f7cf4e9ae74067 Mon Sep 17 00:00:00 2001 From: EdricCua Date: Mon, 30 Dec 2024 12:21:47 +0000 Subject: [PATCH 2/7] Updated docs and implementation Signed-off-by: EdricCua --- go/api/base_client.go | 2 +- go/api/commands.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/go/api/base_client.go b/go/api/base_client.go index 89a729a1ee..62deac9ed3 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -1411,5 +1411,5 @@ func (client *baseClient) Echo(message string) (Result[string], error) { if err != nil { return CreateNilStringResult(), err } - return handleStringOrNullResponse(result) + return handleStringResponse(result) } diff --git a/go/api/commands.go b/go/api/commands.go index 7dcc6b023c..a12d703e07 100644 --- a/go/api/commands.go +++ b/go/api/commands.go @@ -784,12 +784,15 @@ type ConnectionManagementCommands interface { PingWithMessage(message string) (string, error) // Echo the provided message back. + // The command will be routed a random node. + // // Parameters: - // string message + // message - The provided message. // // Return value: // The provided message // + // // For example: // result, err := client.Echo("Hello World") // if err != nil { From 43abd86356262600f62844edceda2168c5a20e10 Mon Sep 17 00:00:00 2001 From: EdricCua Date: Fri, 3 Jan 2025 02:26:41 +0000 Subject: [PATCH 3/7] Get update from main, fix conflict Signed-off-by: EdricCua --- go/api/string_commands.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/go/api/string_commands.go b/go/api/string_commands.go index 2141d3c211..ca0e05c7da 100644 --- a/go/api/string_commands.go +++ b/go/api/string_commands.go @@ -455,4 +455,24 @@ type StringCommands interface { // //[valkey.io]: https://valkey.io/commands/getdel/ GetDel(key string) (Result[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) } From d592a4111d3992a17557d7bf29f2e5cf590d1284 Mon Sep 17 00:00:00 2001 From: EdricCua Date: Mon, 6 Jan 2025 22:26:27 +0000 Subject: [PATCH 4/7] Correct lint issues and test case Signed-off-by: EdricCua --- go/api/string_commands.go | 1 - go/integTest/shared_commands_test.go | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go/api/string_commands.go b/go/api/string_commands.go index ca0e05c7da..6670863ee5 100644 --- a/go/api/string_commands.go +++ b/go/api/string_commands.go @@ -465,7 +465,6 @@ type StringCommands interface { // Return value: // The provided message // - // // For example: // result, err := client.Echo("Hello World") // if err != nil { diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index 92ce636949..3254bd1871 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -4245,10 +4245,11 @@ func (suite *GlideTestSuite) TestZRem() { func (suite *GlideTestSuite) TestEcho() { suite.runWithDefaultClients(func(client api.BaseClient) { - //Test 1: Check if Echo command return the message + // Test 1: Check if Echo command return the message value := "Hello world" + t := suite.T() resultEcho, err := client.Echo(value) - assert.Nil(suite.T(), err) - assert.Equal(suite.T(), value, resultEcho.Value()) + assert.Nil(t, err) + assert.Equal(t, value, resultEcho.Value()) }) } From 0202d3ffb4828cec11242ea1efe30a39953e8b29 Mon Sep 17 00:00:00 2001 From: EdricCua Date: Mon, 6 Jan 2025 23:09:09 +0000 Subject: [PATCH 5/7] Moved Echo comman to connection mngt Signed-off-by: EdricCua --- go/api/connection_management_commands.go | 19 +++++++++++++++++++ go/api/string_commands.go | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/go/api/connection_management_commands.go b/go/api/connection_management_commands.go index 16c08f0a78..f9d4a1dada 100644 --- a/go/api/connection_management_commands.go +++ b/go/api/connection_management_commands.go @@ -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) } diff --git a/go/api/string_commands.go b/go/api/string_commands.go index 6670863ee5..2141d3c211 100644 --- a/go/api/string_commands.go +++ b/go/api/string_commands.go @@ -455,23 +455,4 @@ type StringCommands interface { // //[valkey.io]: https://valkey.io/commands/getdel/ GetDel(key string) (Result[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) } From 29bf3b64b29106731a3ccefb6ebf4bcb62cc3594 Mon Sep 17 00:00:00 2001 From: EdricCua Date: Fri, 17 Jan 2025 00:16:39 +0000 Subject: [PATCH 6/7] Adjustment in response Signed-off-by: EdricCua --- go/api/base_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/api/base_client.go b/go/api/base_client.go index 72992a4e30..b647a010c3 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -2001,5 +2001,5 @@ func (client *baseClient) Echo(message string) (Result[string], error) { if err != nil { return CreateNilStringResult(), err } - return handleStringResponse(result) + return handleStringOrNilResponse(result) } From 2f5ccb3c8c5e990f679669b923e1ee8d245fb998 Mon Sep 17 00:00:00 2001 From: EdricCua Date: Fri, 17 Jan 2025 00:20:52 +0000 Subject: [PATCH 7/7] Move doc to implementation Signed-off-by: EdricCua --- go/api/base_client.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/go/api/base_client.go b/go/api/base_client.go index b647a010c3..196aa4f573 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -1996,6 +1996,26 @@ func (client *baseClient) XPendingWithOptions( return handleXPendingDetailResponse(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 {