Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go: Implement Server Management Command DBSize #2991

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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) DBSize_Success() {
EdricCua marked this conversation as resolved.
Show resolved Hide resolved
client := suite.defaultClient()
result, err := client.DBSize()
assert.Nil(suite.T(), err)
assert.Greater(suite.T(), result, -0)
EdricCua marked this conversation as resolved.
Show resolved Hide resolved
}
Loading