From 980965277e8d0ef24719dabae0f11b41cd80de40 Mon Sep 17 00:00:00 2001 From: Jyotinder Date: Sat, 14 Dec 2024 17:55:05 +0530 Subject: [PATCH 1/2] improve set command implementation --- internal/eval/store_eval.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/internal/eval/store_eval.go b/internal/eval/store_eval.go index 8583cedad..f9a3e26ec 100644 --- a/internal/eval/store_eval.go +++ b/internal/eval/store_eval.go @@ -201,7 +201,7 @@ func evalSET(args []string, store *dstore.Store) *EvalResponse { var oldVal *interface{} key, value = args[0], args[1] - _, oType := getRawStringOrInt(value) + storedValue, oType := getRawStringOrInt(value) for i := 2; i < len(args); i++ { arg := strings.ToUpper(args[i]) @@ -294,14 +294,7 @@ 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: + if oType != object.ObjTypeInt && oType != object.ObjTypeString { return makeEvalError(diceerrors.ErrUnsupportedEncoding(int(oType))) } From 98b81a0c9cc243e159238322320bad3dc7e863eb Mon Sep 17 00:00:00 2001 From: Jyotinder Date: Sat, 14 Dec 2024 22:05:23 +0530 Subject: [PATCH 2/2] cleanup --- internal/eval/store_eval.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/eval/store_eval.go b/internal/eval/store_eval.go index f9a3e26ec..c27597eab 100644 --- a/internal/eval/store_eval.go +++ b/internal/eval/store_eval.go @@ -203,6 +203,10 @@ func evalSET(args []string, store *dstore.Store) *EvalResponse { key, value = args[0], args[1] 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]) switch arg { @@ -294,10 +298,6 @@ func evalSET(args []string, store *dstore.Store) *EvalResponse { } } - if oType != object.ObjTypeInt && oType != object.ObjTypeString { - 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 {