Implement DBSIZE command (#159)

Implement DBSIZE Command - @NicoleStrel
This commit is contained in:
Nicole Streltsov
2025-01-06 05:40:40 -05:00
committed by GitHub
parent 108bf97b4d
commit 8f1330e326
11 changed files with 2158 additions and 3903 deletions

View File

@@ -2909,6 +2909,45 @@ func Test_Generic(t *testing.T) {
}
})
t.Run("Test_HandleDBSIZE", func(t *testing.T) {
conn, err := internal.GetConnection("localhost", port)
if err != nil {
t.Error(err)
return
}
defer func() {
_ = conn.Close()
}()
client := resp.NewConn(conn)
// Populate the store with a few keys
expectedSize := 5
for i := 0; i < expectedSize; i++ {
_, _, err := mockServer.Set(
fmt.Sprintf("DBSizeKey%d", i),
fmt.Sprintf("Value%d", i),
sugardb.SETOptions{},
)
if err != nil {
t.Error(err)
return
}
}
if err = client.WriteArray([]resp.Value{resp.StringValue("DBSIZE")}); err != nil {
t.Error(err)
}
res, _, err := client.ReadValue()
if err != nil {
t.Error(err)
}
if res.Integer() != int(expectedSize) {
t.Errorf("expected dbsize %d, got %d", expectedSize, res.Integer())
}
})
t.Run("Test_HandleGETDEL", func(t *testing.T) {
t.Parallel()
conn, err := internal.GetConnection("localhost", port)