Skip to content

Commit

Permalink
fixed tests + lint
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvyadav1111 committed Nov 5, 2024
1 parent da0c92a commit ff99949
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
3 changes: 2 additions & 1 deletion integration_tests/commands/resp/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func TestSet(t *testing.T) {
func TestSetWithOptions(t *testing.T) {
conn := getLocalConnection()
expiryTime := strconv.FormatInt(time.Now().Add(1*time.Minute).UnixMilli(), 10)
defer FireCommand(conn, "FLUSHDB")
defer conn.Close()

testCases := []TestCase{
Expand Down Expand Up @@ -150,6 +149,8 @@ func TestSetWithOptions(t *testing.T) {
}
})
}

FireCommand(conn, "FLUSHDB")
}

func TestSetWithExat(t *testing.T) {
Expand Down
19 changes: 9 additions & 10 deletions internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func evalSET(args []string, store *dstore.Store) *EvalResponse {
var state exDurationState = Uninitialized
var keepttl bool = false
var getVal bool = false
var getOldVal interface{}

key, value = args[0], args[1]
oType, oEnc := deduceTypeEncoding(value)
Expand Down Expand Up @@ -251,7 +252,9 @@ func evalSET(args []string, store *dstore.Store) *EvalResponse {
exDurationMs = exDuration - utils.GetCurrentTime().UnixMilli()
// If the expiry time is in the past, set exDurationMs to 0
// This will be used to signal immediate expiration
exDurationMs = int64(math.Max(0, float64(exDurationMs)))
if exDurationMs < 0 {
exDurationMs = 0
}
state = Initialized

case XX:
Expand All @@ -274,19 +277,15 @@ func evalSET(args []string, store *dstore.Store) *EvalResponse {
keepttl = true
case GET:
getVal = true
oldVal := evalGET([]string{key}, store)
if oldVal.Error != nil {
return makeEvalError(diceerrors.ErrWrongTypeOperation)
}
getOldVal = oldVal.Result
default:
return makeEvalError(diceerrors.ErrSyntax)
}
}
// get the old value if GET flag is set
var getOldVal interface{}
if getVal {
oldVal := evalGET([]string{key}, store)
if oldVal.Error != nil {
return makeEvalError(diceerrors.ErrWrongTypeOperation)
}
getOldVal = oldVal.Result
}

// Cast the value properly based on the encoding type
var storedValue interface{}
Expand Down

0 comments on commit ff99949

Please sign in to comment.