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

port FLUSHDB command to IronHawk #1457

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions internal/cmd/cmd_flushdb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cmd

import (
"github.com/dicedb/dice/internal/store"
dstore "github.com/dicedb/dice/internal/store"
)

const (
SYNC string = "sync"
ASYNC string = "async"
)

var cFLUSHDB = &DiceDBCommand{
Name: "FLUSHDB",
HelpShort: "FLUSHDB deletes all keys.",
Eval: evalFLUSHDB,
}

func init() {
commandRegistry.AddCommand(cFLUSHDB)
}

// FLUSHDB deletes all keys.
// The function expects no arguments
//
// Parameters:
// - c *Cmd: The command context containing the arguments
// - s *dstore.Store: The data store instance
//
// Returns:
// - *CmdRes: OK or nil
// - error: Error if wrong number of arguments
func evalFLUSHDB(c *Cmd, s *dstore.Store) (*CmdRes, error) {
if len(c.C.Args) != 0 {
return cmdResNil, errWrongArgumentCount("FLUSHDB")
}

store.Reset(s)

return cmdResOK, nil
}
2 changes: 1 addition & 1 deletion internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ func init() {
DiceCmds["EXPIRE"] = expireCmdMeta
DiceCmds["EXPIREAT"] = expireatCmdMeta
DiceCmds["EXPIRETIME"] = expiretimeCmdMeta
DiceCmds["FLUSHDB"] = flushdbCmdMeta
DiceCmds["FLUSHDB"] = flushdbCmdMeta // moved to ironhawk
DiceCmds["GEOADD"] = geoAddCmdMeta
DiceCmds["GEODIST"] = geoDistCmdMeta
DiceCmds["GEOPOS"] = geoPosCmdMeta
Expand Down
6 changes: 3 additions & 3 deletions internal/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type evalMultiShardTestCase struct {
}

func setupTest(store *dstore.Store) *dstore.Store {
dstore.ResetStore(store)
dstore.Reset(store)
return store
}

Expand Down Expand Up @@ -7576,7 +7576,7 @@ func BenchmarkEvalZPOPMIN(b *testing.B) {

for i := 0; i < b.N; i++ {
// Reset the store before each run to avoid contamination
dstore.ResetStore(store)
dstore.Reset(store)
bm.setup(store)
evalZPOPMIN(bm.input, store)
}
Expand Down Expand Up @@ -8649,7 +8649,7 @@ func BenchmarkEvalZPOPMAX(b *testing.B) {

for i := 0; i < b.N; i++ {
// Reset the store before each run to avoid contamination
dstore.ResetStore(store)
dstore.Reset(store)
bm.setup(store)
evalZPOPMAX(bm.input, store)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewStore(cmdWatchChan chan CmdWatchEvent, evictionStrategy EvictionStrategy
return store
}

func ResetStore(store *Store) *Store {
func Reset(store *Store) *Store {
store.numKeys = 0
store.store = NewStoreMap()
store.expires = NewExpireMap()
Expand Down
Loading