Skip to content

Commit

Permalink
GETEXwith EX with big integer reports an error (DiceDB#576)
Browse files Browse the repository at this point in the history
* fixed getex big integer expire issue

* added unit test for GETEX command

* updated unit testcase for GETEX command

* updated maxExDuration logic for getex
  • Loading branch information
Gaurav-Kumar81 authored Sep 16, 2024
1 parent cea0ff8 commit 1098ee0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ func evalGETEX(args []string, store *dstore.Store) []byte {
if err != nil {
return diceerrors.NewErrWithMessage(diceerrors.IntOrOutOfRangeErr)
}
if exDuration <= 0 {
if exDuration <= 0 || exDuration > maxExDuration {
return diceerrors.NewErrExpireTime("GETEX")
}

Expand Down
32 changes: 32 additions & 0 deletions internal/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func TestEval(t *testing.T) {
testEvalHLEN(t, store)
testEvalSELECT(t, store)
testEvalLLEN(t, store)
testEvalGETEX(t, store)
}

func testEvalPING(t *testing.T, store *dstore.Store) {
Expand Down Expand Up @@ -123,6 +124,37 @@ func testEvalSET(t *testing.T, store *dstore.Store) {
runEvalTests(t, tests, evalSET, store)
}

func testEvalGETEX(t *testing.T, store *dstore.Store) {
tests := map[string]evalTestCase{

"key val pair and valid EX": {
setup: func() {
key := "foo"
value := "bar"
obj := &object.Obj{
Value: value,
}
store.Put(key, obj)
},
input: []string{"foo", Ex, "10"},
output: clientio.Encode("bar", false),
},
"key val pair and invalid EX": {
setup: func() {
key := "foo"
value := "bar"
obj := &object.Obj{
Value: value,
}
store.Put(key, obj)
},
input: []string{"foo", Ex, "10000000000000000"},
output: []byte("-ERR invalid expire time in 'getex' command\r\n")},
}

runEvalTests(t, tests, evalGETEX, store)
}

func testEvalMSET(t *testing.T, store *dstore.Store) {
tests := map[string]evalTestCase{
"nil value": {input: nil, output: []byte("-ERR wrong number of arguments for 'mset' command\r\n")},
Expand Down

0 comments on commit 1098ee0

Please sign in to comment.