Skip to content

Commit

Permalink
Add random content
Browse files Browse the repository at this point in the history
Signed-off-by: MikeMwita <[email protected]>
  • Loading branch information
MikeMwita committed Oct 14, 2024
1 parent 12622e2 commit 89c8590
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
12 changes: 4 additions & 8 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type BaseClient interface {
HashCommands
ListCommands
ConnectionManagementCommands
GenericBaseCommands
// Close terminates the client by closing all associated resources.
Close()
}
Expand Down Expand Up @@ -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)
}
21 changes: 1 addition & 20 deletions go/api/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions go/api/generic_commands.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion go/integTest/shared_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 89c8590

Please sign in to comment.