Skip to content

Commit

Permalink
new command for multishard keys
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinKul28 committed Nov 12, 2024
1 parent dc52653 commit 1f32b73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
12 changes: 10 additions & 2 deletions internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,16 @@ var (
}

keysCmdMeta = DiceCmdMeta{
Name: "KEYS",
Name: "KEYS",
Info: "KEYS command is used to get all the keys in the database. Complexity is O(n) where n is the number of keys in the database.",
Eval: evalKeys,
Arity: 1,
}

multiKeysCmdMeta = DiceCmdMeta{
Name: "KEYSPERSHARD",
Info: "KEYS command is used to get all the keys in the database. Complexity is O(n) where n is the number of keys in the database.",
NewEval: evalKeys,
NewEval: evalKeysPerShard,
IsMigrated: true,
Arity: 1,
}
Expand Down Expand Up @@ -1490,6 +1497,7 @@ func init() {
DiceCmds["JSON.TOGGLE"] = jsontoggleCmdMeta
DiceCmds["JSON.TYPE"] = jsontypeCmdMeta
DiceCmds["KEYS"] = keysCmdMeta
DiceCmds["KEYSPERSHARD"] = multiKeysCmdMeta
DiceCmds["LATENCY"] = latencyCmdMeta
DiceCmds["LLEN"] = llenCmdMeta
DiceCmds["LPOP"] = lpopCmdMeta
Expand Down
16 changes: 16 additions & 0 deletions internal/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,22 @@ func evalCommandList(args []string) []byte {
return clientio.Encode(cmds, false)
}

// evalKeys returns the list of keys that match the pattern should be the only param in args
// TODO: Needs to be removed after http and websocket migrated to the multithreading
func evalKeys(args []string, store *dstore.Store) []byte {
if len(args) != 1 {
return diceerrors.NewErrArity("KEYS")
}

pattern := args[0]
keys, err := store.Keys(pattern)
if err != nil {
return clientio.Encode(err, false)
}

return clientio.Encode(keys, false)
}

// evalCommandCount returns a number of commands supported by DiceDB
func evalCommandCount(args []string) []byte {
if len(args) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2115,7 +2115,7 @@ func evalPTTL(args []string, store *dstore.Store) *EvalResponse {
}

// evalKeys returns the list of keys that match the pattern should be the only param in args
func evalKeys(args []string, store *dstore.Store) *EvalResponse {
func evalKeysPerShard(args []string, store *dstore.Store) *EvalResponse {
if len(args) != 1 {
return makeEvalError(diceerrors.ErrWrongArgumentCount("KEYS"))
}
Expand Down

0 comments on commit 1f32b73

Please sign in to comment.