Skip to content

Commit

Permalink
Improves SET command implementation (#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
JyotinderSingh authored Dec 14, 2024
1 parent 45f7f55 commit c3d5970
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ func evalSET(args []string, store *dstore.Store) *EvalResponse {
var oldVal *interface{}

key, value = args[0], args[1]
_, oType := getRawStringOrInt(value)
storedValue, oType := getRawStringOrInt(value)

if oType != object.ObjTypeInt && oType != object.ObjTypeString {
return makeEvalError(diceerrors.ErrUnsupportedEncoding(int(oType)))
}

for i := 2; i < len(args); i++ {
arg := strings.ToUpper(args[i])
Expand Down Expand Up @@ -310,17 +314,6 @@ func evalSET(args []string, store *dstore.Store) *EvalResponse {
}
}

// Cast the value properly based on the encoding type
var storedValue interface{}
switch oType {
case object.ObjTypeInt:
storedValue, _ = strconv.ParseInt(value, 10, 64)
case object.ObjTypeString:
storedValue = value
default:
return makeEvalError(diceerrors.ErrUnsupportedEncoding(int(oType)))
}

// putting the k and value in a Hash Table
store.Put(key, store.NewObj(storedValue, exDurationMs, oType), dstore.WithKeepTTL(keepttl))
if oldVal != nil {
Expand Down

0 comments on commit c3d5970

Please sign in to comment.