Skip to content

Commit

Permalink
FIX: Delete Command with 0 Arguments (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanshavenger authored Oct 6, 2024
1 parent 6abbe37 commit e2990b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion integration_tests/commands/async/del_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func TestDel(t *testing.T) {
commands: []string{"GET k3", "DEL k3"},
expected: []interface{}{"(nil)", int64(0)},
},
{
name: "DEL with no keys or arguments",
commands: []string{"DEL"},
expected: []interface{}{"ERR wrong number of arguments for 'del' command"},
},
}

for _, tc := range testCases {
Expand All @@ -45,4 +50,4 @@ func TestDel(t *testing.T) {
}
})
}
}
}
4 changes: 4 additions & 0 deletions internal/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,10 @@ func evalTTL(args []string, store *dstore.Store) []byte {
func evalDEL(args []string, store *dstore.Store) []byte {
var countDeleted = 0

if len(args) < 1 {
return diceerrors.NewErrArity("DEL")
}

for _, key := range args {
if ok := store.Del(key); ok {
countDeleted++
Expand Down
4 changes: 2 additions & 2 deletions internal/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1937,12 +1937,12 @@ func testEvalDel(t *testing.T, store *dstore.Store) {
"nil value": {
setup: func() {},
input: nil,
output: []byte(":0\r\n"),
output: clientio.Encode(errors.New("ERR wrong number of arguments for 'del' command"), false),
},
"empty array": {
setup: func() {},
input: []string{},
output: []byte(":0\r\n"),
output: clientio.Encode(errors.New("ERR wrong number of arguments for 'del' command"), false),
},
"key does not exist": {
setup: func() {},
Expand Down

0 comments on commit e2990b5

Please sign in to comment.