diff --git a/go/api/glide_client.go b/go/api/glide_client.go index a90575c767..801a6c4b3d 100644 --- a/go/api/glide_client.go +++ b/go/api/glide_client.go @@ -67,3 +67,26 @@ func (client *glideClient) Select(index int64) (string, error) { return handleStringResponse(result) } + +// Returns the number of keys in the currently selected database. +// +// Return value: +// +// The number of keys in the currently selected database. +// +// Example: +// +// result, err := client.DBSize() +// if err != nil { +// // handle error +// } +// fmt.Println(result) // Output: 1 +// +// [valkey.io]: https://valkey.io/commands/dbsize/ +func (client *glideClient) DBSize() (int64, error) { + result, err := client.executeCommand(C.DBSize, []string{}) + if err != nil { + return defaultIntResponse, err + } + return handleIntResponse(result) +} diff --git a/go/api/server_management_commands.go b/go/api/server_management_commands.go index 37954f543a..5dcd17c166 100644 --- a/go/api/server_management_commands.go +++ b/go/api/server_management_commands.go @@ -61,4 +61,6 @@ type ServerManagementCommands interface { // // [valkey.io]: https://valkey.io/commands/config-set/ ConfigSet(parameters map[string]string) (string, error) + + DBSize() (int64, error) } diff --git a/go/integTest/standalone_commands_test.go b/go/integTest/standalone_commands_test.go index 3c298f1ee6..a3e6d582c5 100644 --- a/go/integTest/standalone_commands_test.go +++ b/go/integTest/standalone_commands_test.go @@ -388,3 +388,10 @@ func (suite *GlideTestSuite) TestSortReadOnlyWithOptions_SuccessfulSortByWeightA assert.Equal(suite.T(), "item1", sortResult[3].Value()) assert.Equal(suite.T(), "item3", sortResult[5].Value()) } + +func (suite *GlideTestSuite) TestDBSize() { + client := suite.defaultClient() + result, err := client.DBSize() + assert.Nil(suite.T(), err) + assert.Greater(suite.T(), result, int64(0)) +}