Skip to content

Commit

Permalink
Go: Implement Server Management Command DBSize (#2991)
Browse files Browse the repository at this point in the history
* Implement DBSize Command

Signed-off-by: EdricCua <[email protected]>
  • Loading branch information
EdricCua authored Jan 23, 2025
1 parent a0494a4 commit 46d3d26
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions go/api/server_management_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions go/integTest/standalone_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 46d3d26

Please sign in to comment.