From 89c8590343440346df6da9c53bb3bd7a6d3d776f Mon Sep 17 00:00:00 2001 From: MikeMwita Date: Thu, 10 Oct 2024 13:07:58 +0300 Subject: [PATCH] Add random content Signed-off-by: MikeMwita --- go/api/base_client.go | 12 ++++------ go/api/commands.go | 21 +----------------- go/api/generic_commands.go | 33 ++++++++++++++++++++++++++++ go/integTest/shared_commands_test.go | 2 +- 4 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 go/api/generic_commands.go diff --git a/go/api/base_client.go b/go/api/base_client.go index 96ed5fc73d..088db52614 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -25,6 +25,7 @@ type BaseClient interface { HashCommands ListCommands ConnectionManagementCommands + GenericBaseCommands // Close terminates the client by closing all associated resources. Close() } @@ -623,16 +624,11 @@ func (client *baseClient) PingWithMessage(message string) (string, error) { return response.Value(), nil } -func (client *baseClient) Del(keys []string) (int64, error) { +func (client *baseClient) Del(keys []string) (Result[int64], error) { result, err := client.executeCommand(C.Del, keys) if err != nil { - return 0, err - } - - deletedCount, handleErr := handleLongResponse(result) - if handleErr != nil { - return 0, handleErr + return CreateNilInt64Result(), err } - return deletedCount.Value(), nil + return handleLongResponse(result) } diff --git a/go/api/commands.go b/go/api/commands.go index 8bc524166e..1d00ff8270 100644 --- a/go/api/commands.go +++ b/go/api/commands.go @@ -428,6 +428,7 @@ type StringCommands interface { // // [valkey.io]: https://valkey.io/commands/lcs/ LCS(key1 string, key2 string) (Result[string], error) + // GetDel gets the value associated with the given key and deletes the key. // // Parameters: @@ -442,26 +443,6 @@ type StringCommands interface { // //[valkey.io]: https://valkey.io/commands/getdel/ GetDel(key string) (Result[string], error) - // Del removes the specified keys from the database. A key is ignored if it does not exist. - // - // Note: - //When in cluster mode, the command may route to multiple nodes when `keys` map to different hash slots. - // - // Parameters: - // keys - One or more keys to delete. - // - // Return value: - // Returns the number of keys that were removed. - // - // Example: - // result, err := client.Del([]string{"key1", "key2", "key3"}) - // if err != nil { - // // handle error - // } - // fmt.Println(result) // Output: 2 - // - // [valkey.io]: https://valkey.io/commands/del/ - Del(keys []string) (int64, error) } // HashCommands supports commands and transactions for the "Hash Commands" group for standalone and cluster diff --git a/go/api/generic_commands.go b/go/api/generic_commands.go new file mode 100644 index 0000000000..82620610a2 --- /dev/null +++ b/go/api/generic_commands.go @@ -0,0 +1,33 @@ +// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 + +package api + +// Supports commands and transactions for the "List Commands" group for standalone and cluster clients. +// +// See [valkey.io] for details. +// +// GenericBaseCommands defines an interface for the "Generic Commands". +// +// [valkey.io]: https://valkey.io/commands/?group=Generic +type GenericBaseCommands interface { + // Del removes the specified keys from the database. A key is ignored if it does not exist. + // + // Note: + //When in cluster mode, the command may route to multiple nodes when `keys` map to different hash slots. + // + // Parameters: + // keys - One or more keys to delete. + // + // Return value: + // Returns the number of keys that were removed. + // + // Example: + // result, err := client.Del([]string{"key1", "key2", "key3"}) + // if err != nil { + // // handle error + // } + // fmt.Println(result) // Output: 2 + // + // [valkey.io]: https://valkey.io/commands/del/ + Del(keys []string) (Result[int64], error) +} diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index 2298ffe8ed..3e4b4a67d5 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -1529,7 +1529,7 @@ func (suite *GlideTestSuite) TestDel_MultipleKeys() { deletedCount, err := client.Del([]string{key1, key2, key3}) assert.Nil(suite.T(), err) - assert.Equal(suite.T(), int64(3), deletedCount) + assert.Equal(suite.T(), int64(3), deletedCount.Value()) result1, err1 := client.Get(key1) result2, err2 := client.Get(key2)