diff --git a/go/api/glide_client.go b/go/api/glide_client.go index 51ea9ef4b4..11edfeca0b 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 3653f17903..0084f31a66 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 2d4a0ec31c..4c3f8a4f73 100644 --- a/go/integTest/standalone_commands_test.go +++ b/go/integTest/standalone_commands_test.go @@ -384,3 +384,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)) +}