diff --git a/integration_tests/commands/mset_test.go b/integration_tests/commands/mset_test.go index a86b87964..c93810b33 100644 --- a/integration_tests/commands/mset_test.go +++ b/integration_tests/commands/mset_test.go @@ -45,3 +45,54 @@ func TestMset(t *testing.T) { }) } } +func TestMSETInconsistency(t *testing.T) { + + conn := getLocalConnection() + defer conn.Close() + + testCases := []struct { + name string + commands []string + expected []interface{} + }{ + { + name: "MSET with one key-value pair", + commands: []string{"MSET k1 v1", "GET k1"}, + expected: []interface{}{"OK", "v1"}, + }, + { + name: "MSET with multiple key-value pairs", + commands: []string{"MSET k1 v1 k2 v2", "GET k1", "GET k2"}, + expected: []interface{}{"OK", "v1", "v2"}, + }, + { + name: "MSET with odd number of arguments", + commands: []string{"MSET k1 v1 k2"}, + expected: []interface{}{"ERR wrong number of arguments for 'mset' command"}, + }, + { + name: "MSET with multiple key-value pairs", + commands: []string{"MSET k1 v1 k2 v2", "GET k1", "GET k2"}, + expected: []interface{}{"OK", "v1", "v2"}, + }, + { + name: "MSET with integers arguments", + commands: []string{"MSET key1 12345 key2 67890", "GET key1", "GET key2"}, + expected: []interface{}{"OK", int64(12345), int64(67890)}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // deleteTestKeys([]string{"k1", "k2"}, store) + FireCommand(conn, "DEL k1") + FireCommand(conn, "DEL k1") + + for i, cmd := range tc.commands { + result := FireCommand(conn, cmd) + assert.DeepEqual(t, tc.expected[i], result) + } + }) + } + +} diff --git a/internal/eval/eval.go b/internal/eval/eval.go index 399791a05..e4b346c64 100644 --- a/internal/eval/eval.go +++ b/internal/eval/eval.go @@ -239,7 +239,16 @@ func evalMSET(args []string, store *dstore.Store) []byte { for i := 0; i < len(args); i += 2 { key, value := args[i], args[i+1] oType, oEnc := deduceTypeEncoding(value) - insertMap[key] = store.NewObj(value, exDurationMs, oType, oEnc) + var storedValue interface{} + switch oEnc { + case object.ObjEncodingInt: + storedValue, _ = strconv.ParseInt(value, 10, 64) + case object.ObjEncodingEmbStr, object.ObjEncodingRaw: + storedValue = value + default: + return clientio.Encode(fmt.Errorf("ERR unsupported encoding: %d", oEnc), false) + } + insertMap[key] = store.NewObj(storedValue, exDurationMs, oType, oEnc) } store.PutAll(insertMap) diff --git a/internal/eval/eval_test.go b/internal/eval/eval_test.go index d13de2d77..0bcbd65e8 100644 --- a/internal/eval/eval_test.go +++ b/internal/eval/eval_test.go @@ -2586,3 +2586,10 @@ func testEvalCOMMAND(t *testing.T, store *dstore.Store) { runEvalTests(t, tests, evalCommand, store) } +func TestMSETConsistency(t *testing.T) { + store := dstore.NewStore(nil) + evalMSET([]string{"KEY", "VAL", "KEY2", "VAL2"}, store) + + assert.Equal(t, "VAL", store.Get("KEY").Value) + assert.Equal(t, "VAL2", store.Get("KEY2").Value) +}