Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves SET command implementation #1371

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,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 @@ -294,17 +298,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
Loading