Skip to content

Commit 46d3d26

Browse files
authored
Go: Implement Server Management Command DBSize (valkey-io#2991)
* Implement DBSize Command Signed-off-by: EdricCua <[email protected]>
1 parent a0494a4 commit 46d3d26

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

go/api/glide_client.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,26 @@ func (client *glideClient) Select(index int64) (string, error) {
6767

6868
return handleStringResponse(result)
6969
}
70+
71+
// Returns the number of keys in the currently selected database.
72+
//
73+
// Return value:
74+
//
75+
// The number of keys in the currently selected database.
76+
//
77+
// Example:
78+
//
79+
// result, err := client.DBSize()
80+
// if err != nil {
81+
// // handle error
82+
// }
83+
// fmt.Println(result) // Output: 1
84+
//
85+
// [valkey.io]: https://valkey.io/commands/dbsize/
86+
func (client *glideClient) DBSize() (int64, error) {
87+
result, err := client.executeCommand(C.DBSize, []string{})
88+
if err != nil {
89+
return defaultIntResponse, err
90+
}
91+
return handleIntResponse(result)
92+
}

go/api/server_management_commands.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@ type ServerManagementCommands interface {
6161
//
6262
// [valkey.io]: https://valkey.io/commands/config-set/
6363
ConfigSet(parameters map[string]string) (string, error)
64+
65+
DBSize() (int64, error)
6466
}

go/integTest/standalone_commands_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,10 @@ func (suite *GlideTestSuite) TestSortReadOnlyWithOptions_SuccessfulSortByWeightA
384384
assert.Equal(suite.T(), "item1", sortResult[3].Value())
385385
assert.Equal(suite.T(), "item3", sortResult[5].Value())
386386
}
387+
388+
func (suite *GlideTestSuite) TestDBSize() {
389+
client := suite.defaultClient()
390+
result, err := client.DBSize()
391+
assert.Nil(suite.T(), err)
392+
assert.Greater(suite.T(), result, int64(0))
393+
}

0 commit comments

Comments
 (0)