diff --git a/Makefile b/Makefile index 41432e024..9e44d0bad 100644 --- a/Makefile +++ b/Makefile @@ -29,12 +29,16 @@ build: ## generate the dicedb binary for the current OS and architecture @echo "Building for $(GOOS)/$(GOARCH)" CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o ./dicedb +build-debug: ## generate the dicedb binary for the current OS and architecture + @echo "Building for $(GOOS)/$(GOARCH)" + CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -gcflags="all=-N -l" -o ./dicedb + ##@ Testing # Changing the parallel package count to 1 due to a possible race condition which causes the tests to get stuck. # TODO: Fix the tests to run in parallel, and remove the -p=1 flag. test: ## run the integration tests - go test -v -race -count=1 -p=1 ./integration_tests/... + go test -race -count=1 -p=1 ./integration_tests/... test-one: ## run a single integration test function by name (e.g. make test-one TEST_FUNC=TestSetGet) go test -v -race -count=1 --run $(TEST_FUNC) ./integration_tests/... diff --git a/docs/src/content/docs/commands/OBJECT.md b/docs/src/content/docs/commands/OBJECT.md index 5929ae5d9..0256f7918 100644 --- a/docs/src/content/docs/commands/OBJECT.md +++ b/docs/src/content/docs/commands/OBJECT.md @@ -16,7 +16,6 @@ OBJECT - ``: The specific operation you want to perform on the key. The available subcommands are: - `REFCOUNT`: Returns the number of references of the value associated with the specified key. - - `ENCODING`: Returns the internal representation (encoding) used to store the value associated with the specified key. - `IDLETIME`: Returns the number of seconds since the object was last accessed. - `FREQ`: Returns the access frequency of a key, if the LFU (Least Frequently Used) eviction policy is enabled. @@ -27,7 +26,6 @@ OBJECT The return value depends on the subcommand used: - `REFCOUNT`: Returns an integer representing the reference count of the key. -- `ENCODING`: Returns a string representing the encoding type of the key. - `IDLETIME`: Returns an integer representing the idle time in seconds. - `FREQ`: Returns an integer representing the access frequency of the key. @@ -38,7 +36,6 @@ When the `OBJECT` command is executed, DiceDB inspects the specified key and ret ### Subcommand Behaviours - `REFCOUNT`: This subcommand returns the number of references to the key's value. A higher reference count indicates that the value is being shared among multiple keys or clients. -- `ENCODING`: This subcommand reveals the internal representation of the key's value, such as `int`, `embstr`, `raw`, `ziplist`, `linkedlist`, etc. - `IDLETIME`: This subcommand provides the time in seconds since the key was last accessed. It is useful for identifying stale keys. - `FREQ`: This subcommand returns the access frequency of the key, which is useful when using the LFU eviction policy. @@ -61,15 +58,6 @@ OBJECT REFCOUNT mykey This response indicates that the value associated with `mykey` has a reference count of 1. -### Using the `ENCODING` Subcommand - -```bash -OBJECT ENCODING mykey -"embstr" -``` - -This response indicates that the value associated with `mykey` is stored using the `embstr` encoding. - ### Using the `IDLETIME` Subcommand ```bash diff --git a/docs/src/pages/redis-compatability.astro b/docs/src/pages/redis-compatability.astro index ff62bb602..238253714 100644 --- a/docs/src/pages/redis-compatability.astro +++ b/docs/src/pages/redis-compatability.astro @@ -776,11 +776,6 @@ const description = ""; MSETNX - - - OBJECT|ENCODING - - OBJECT|FREQ diff --git a/integration_tests/commands/resp/deque_test.go b/integration_tests/commands/resp/deque_test.go index c935e95d0..db69db3ce 100644 --- a/integration_tests/commands/resp/deque_test.go +++ b/integration_tests/commands/resp/deque_test.go @@ -468,7 +468,7 @@ func TestLInsert(t *testing.T) { { name: "LINSERT wrong type", cmds: []string{"SET k1 val1", "LINSERT k1 before val1 val2"}, - expect: []any{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []any{"OK", "-WRONGTYPE Operation against a key holding the wrong kind of value"}, }, } @@ -512,7 +512,7 @@ func TestLRange(t *testing.T) { { name: "LRANGE wrong type", cmds: []string{"SET k1 val1", "LRANGE k1 0 100"}, - expect: []any{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []any{"OK", "-WRONGTYPE Operation against a key holding the wrong kind of value"}, }, } diff --git a/integration_tests/commands/resp/object_test.go b/integration_tests/commands/resp/object_test.go index 9e528bc6e..cd6c9cd74 100644 --- a/integration_tests/commands/resp/object_test.go +++ b/integration_tests/commands/resp/object_test.go @@ -11,7 +11,6 @@ func TestObjectCommand(t *testing.T) { conn := getLocalConnection() defer conn.Close() defer FireCommand(conn, "FLUSHDB") - simpleJSON := `{"name":"John","age":30}` testCases := []struct { name string @@ -29,86 +28,6 @@ func TestObjectCommand(t *testing.T) { delay: []time.Duration{0, 2 * time.Second, 3 * time.Second, 0, 0}, cleanup: []string{"DEL foo"}, }, - { - name: "Object Encoding check for raw", - commands: []string{"SET foo foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar", "OBJECT ENCODING foo"}, - expected: []interface{}{"OK", "raw"}, - assertType: []string{"equal", "equal"}, - delay: []time.Duration{0, 0}, - cleanup: []string{"DEL foo"}, - }, - { - name: "Object Encoding check for int", - commands: []string{"SET foo 1", "OBJECT ENCODING foo"}, - expected: []interface{}{"OK", "int"}, - assertType: []string{"equal", "equal"}, - delay: []time.Duration{0, 0}, - cleanup: []string{"DEL foo"}, - }, - { - name: "Object Encoding check for embstr", - commands: []string{"SET foo bar", "OBJECT ENCODING foo"}, - expected: []interface{}{"OK", "embstr"}, - assertType: []string{"equal", "equal"}, - delay: []time.Duration{0, 0}, - cleanup: []string{"DEL foo"}, - }, - { - name: "Object Encoding check for deque", - commands: []string{"LPUSH listKey 'value1'", "LPUSH listKey 'value2'", "OBJECT ENCODING listKey"}, - expected: []interface{}{int64(1), int64(2), "deque"}, - assertType: []string{"assert", "assert", "equal"}, - delay: []time.Duration{0, 0, 0}, - cleanup: []string{"DEL listKey"}, - }, - { - name: "Object Encoding check for bf", - commands: []string{"BF.ADD bloomkey value1", "BF.ADD bloomkey value2", "OBJECT ENCODING bloomkey"}, - expected: []interface{}{int64(1), int64(1), "bf"}, - assertType: []string{"assert", "assert", "equal"}, - delay: []time.Duration{0, 0, 0}, - cleanup: []string{"DEL bloomkey"}, - }, - { - name: "Object Encoding check for json", - commands: []string{`JSON.SET k10 $ ` + simpleJSON, "OBJECT ENCODING k10"}, - expected: []interface{}{"OK", "json"}, - assertType: []string{"equal", "equal"}, - delay: []time.Duration{0, 0}, - cleanup: []string{"DEL k10"}, - }, - { - name: "Object Encoding check for bytearray", - commands: []string{"SETBIT kbitset 0 1", "SETBIT kbitset 1 0", "SETBIT kbitset 2 1", "OBJECT ENCODING kbitset"}, - expected: []interface{}{int64(0), int64(0), int64(0), "bytearray"}, - assertType: []string{"assert", "assert", "assert", "equal"}, - delay: []time.Duration{0, 0, 0, 0}, - cleanup: []string{"DEL kbitset"}, - }, - { - name: "Object Encoding check for hashmap", - commands: []string{"HSET hashKey hKey hValue", "OBJECT ENCODING hashKey"}, - expected: []interface{}{int64(1), "hashmap"}, - assertType: []string{"assert", "equal"}, - delay: []time.Duration{0, 0}, - cleanup: []string{"DEL hashKey"}, - }, - { - name: "Object Encoding check for btree", - commands: []string{"ZADD btreekey 1 'member1' 2 'member2'", "OBJECT ENCODING btreekey"}, - expected: []interface{}{int64(2), "btree"}, - assertType: []string{"equal", "equal"}, - delay: []time.Duration{0, 0}, - cleanup: []string{"DEL btreekey"}, - }, - { - name: "Object Encoding check for setstr", - commands: []string{"SADD skey one two three", "OBJECT ENCODING skey"}, - expected: []interface{}{int64(3), "setstr"}, - assertType: []string{"assert", "equal"}, - delay: []time.Duration{0, 0}, - cleanup: []string{"DEL skey"}, - }, } for _, tc := range testCases { diff --git a/internal/eval/bloom.go b/internal/eval/bloom.go index fc5ce91b8..35b893705 100644 --- a/internal/eval/bloom.go +++ b/internal/eval/bloom.go @@ -298,13 +298,10 @@ func GetBloomFilter(key string, store *dstore.Store) (*Bloom, error) { if obj == nil { return nil, nil } - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeBitSet); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeBF); err != nil { return nil, diceerrors.ErrWrongTypeOperation } - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingBF); err != nil { - return nil, diceerrors.ErrWrongTypeOperation - } return obj.Value.(*Bloom), nil } @@ -319,7 +316,7 @@ func CreateBloomFilter(key string, store *dstore.Store, opts *BloomOpts) (*Bloom if opts == nil { opts = defaultBloomOpts() } - obj := store.NewObj(newBloomFilter(opts), -1, object.ObjTypeBitSet, object.ObjEncodingBF) + obj := store.NewObj(newBloomFilter(opts), -1, object.ObjTypeBF) store.Put(key, obj) return obj.Value.(*Bloom), nil } diff --git a/internal/eval/bytearray.go b/internal/eval/bytearray.go index fdc5eaab9..91e9edc40 100644 --- a/internal/eval/bytearray.go +++ b/internal/eval/bytearray.go @@ -36,12 +36,12 @@ func NewByteArrayFromObj(obj *object.Obj) (*ByteArray, error) { } func getValueAsByteSlice(obj *object.Obj) ([]byte, error) { - oType, oEnc := object.ExtractTypeEncoding(obj) + oType := object.ExtractType(obj) switch oType { case object.ObjTypeInt: return []byte(strconv.FormatInt(obj.Value.(int64), 10)), nil case object.ObjTypeString: - return getStringValueAsByteSlice(obj, oEnc) + return getStringValueAsByteSlice(obj) // TODO: Have this case as SETBIT stores values encoded as byte arrays. Need to investigate this further. case object.ObjTypeByteArray: return getByteArrayValueAsByteSlice(obj) @@ -50,16 +50,16 @@ func getValueAsByteSlice(obj *object.Obj) ([]byte, error) { } } -func getStringValueAsByteSlice(obj *object.Obj, oEnc uint8) ([]byte, error) { - switch oEnc { - case object.ObjEncodingInt: +func getStringValueAsByteSlice(obj *object.Obj) ([]byte, error) { + switch obj.Type { + case object.ObjTypeInt: intVal, ok := obj.Value.(int64) if !ok { return nil, errors.New("expected integer value but got another type") } return []byte(strconv.FormatInt(intVal, 10)), nil - case object.ObjEncodingEmbStr, object.ObjEncodingRaw: + case object.ObjTypeString: strVal, ok := obj.Value.(string) if !ok { return nil, errors.New("expected string value but got another type") @@ -67,7 +67,7 @@ func getStringValueAsByteSlice(obj *object.Obj, oEnc uint8) ([]byte, error) { return []byte(strVal), nil default: - return nil, fmt.Errorf("unsupported encoding type: %d", oEnc) + return nil, fmt.Errorf("unsupported type type: %d", obj.Type) } } @@ -81,12 +81,12 @@ func getByteArrayValueAsByteSlice(obj *object.Obj) ([]byte, error) { } // ByteSliceToObj converts a byte slice to an Obj of the specified type and encoding -func ByteSliceToObj(store *dstore.Store, oldObj *object.Obj, b []byte, objType, encoding uint8) (*object.Obj, error) { +func ByteSliceToObj(store *dstore.Store, oldObj *object.Obj, b []byte, objType uint8) (*object.Obj, error) { switch objType { case object.ObjTypeInt: return ByteSliceToIntObj(store, oldObj, b) case object.ObjTypeString: - return ByteSliceToStringObj(store, oldObj, b, encoding) + return ByteSliceToStringObj(store, oldObj, b) case object.ObjTypeByteArray: return ByteSliceToByteArrayObj(store, oldObj, b) default: @@ -100,19 +100,12 @@ func ByteSliceToIntObj(store *dstore.Store, oldObj *object.Obj, b []byte) (*obje if err != nil { return store.NewObj(string(b), -1, object.ObjTypeString, object.ObjEncodingEmbStr), nil } - return store.NewObj(intVal, -1, object.ObjTypeInt, object.ObjEncodingInt), nil + return store.NewObj(intVal, -1, object.ObjTypeInt), nil } // ByteSliceToStringObj converts a byte slice to an Obj with a string value -func ByteSliceToStringObj(store *dstore.Store, oldObj *object.Obj, b []byte, encoding uint8) (*object.Obj, error) { - switch encoding { - case object.ObjEncodingInt: - return ByteSliceToIntObj(store, oldObj, b) - case object.ObjEncodingEmbStr, object.ObjEncodingRaw: - return store.NewObj(string(b), -1, object.ObjTypeString, object.ObjEncodingEmbStr), nil - default: - return nil, fmt.Errorf("unsupported encoding type") - } +func ByteSliceToStringObj(store *dstore.Store, oldObj *object.Obj, b []byte) (*object.Obj, error) { + return store.NewObj(string(b), -1, object.ObjTypeString), nil } // ByteSliceToByteArrayObj converts a byte slice to an Obj with a ByteArray value @@ -121,7 +114,7 @@ func ByteSliceToByteArrayObj(store *dstore.Store, oldObj *object.Obj, b []byte) data: b, Length: int64(len(b)), } - return store.NewObj(byteValue, -1, object.ObjTypeByteArray, object.ObjEncodingByteArray), nil + return store.NewObj(byteValue, -1, object.ObjTypeByteArray), nil } // SetBit sets the bit at the given position to the specified value diff --git a/internal/eval/countminsketch.go b/internal/eval/countminsketch.go index ecafa3709..27e417851 100644 --- a/internal/eval/countminsketch.go +++ b/internal/eval/countminsketch.go @@ -511,7 +511,7 @@ func createCountMinSketch(key string, opts *CountMinSketchOpts, store *dstore.St return diceerrors.NewErr("key already exists") } - obj = store.NewObj(newCountMinSketch(opts), -1, object.ObjTypeCountMinSketch, object.ObjEncodingMatrix) + obj = store.NewObj(newCountMinSketch(opts), -1, object.ObjTypeCountMinSketch) store.Put(key, obj) return nil @@ -526,11 +526,7 @@ func getCountMinSketch(key string, store *dstore.Store) (*CountMinSketch, error) return nil, diceerrors.NewErr("key does not exist") } - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeCountMinSketch); err != nil { - return nil, err - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingMatrix); err != nil { + if err := object.AssertTypeWithError(obj.Type, object.ObjTypeCountMinSketch); err != nil { return nil, err } diff --git a/internal/eval/dump_restore.go b/internal/eval/dump_restore.go index 0c1428127..29d87159d 100644 --- a/internal/eval/dump_restore.go +++ b/internal/eval/dump_restore.go @@ -36,7 +36,7 @@ func readString(data []byte) (*object.Obj, error) { return nil, err } - return &object.Obj{TypeEncoding: object.ObjTypeString, Value: string(strBytes)}, nil + return &object.Obj{Type: object.ObjTypeString, Value: string(strBytes)}, nil } func readInt(data []byte) (*object.Obj, error) { @@ -45,14 +45,14 @@ func readInt(data []byte) (*object.Obj, error) { return nil, err } - return &object.Obj{TypeEncoding: object.ObjTypeInt, Value: intVal}, nil + return &object.Obj{Type: object.ObjTypeInt, Value: intVal}, nil } func rdbSerialize(obj *object.Obj) ([]byte, error) { var buf bytes.Buffer buf.WriteByte(0x09) - switch object.GetType(obj.TypeEncoding) { + switch obj.Type { case object.ObjTypeString: str, ok := obj.Value.(string) if !ok { diff --git a/internal/eval/eval.go b/internal/eval/eval.go index ab0190dee..7c1173b1f 100644 --- a/internal/eval/eval.go +++ b/internal/eval/eval.go @@ -165,17 +165,17 @@ func evalMSET(args []string, store *dstore.Store) []byte { insertMap := make(map[string]*object.Obj, len(args)/2) for i := 0; i < len(args); i += 2 { key, value := args[i], args[i+1] - oType, oEnc := deduceTypeEncoding(value) + oType := deduceType(value) var storedValue interface{} - switch oEnc { - case object.ObjEncodingInt: + switch oType { + case object.ObjTypeInt: storedValue, _ = strconv.ParseInt(value, 10, 64) - case object.ObjEncodingEmbStr, object.ObjEncodingRaw: + case object.ObjTypeString: storedValue = value default: - return clientio.Encode(fmt.Errorf("ERR unsupported encoding: %d", oEnc), false) + return clientio.Encode(fmt.Errorf("ERR unsupported type: %d", oType), false) } - insertMap[key] = store.NewObj(storedValue, exDurationMs, oType, oEnc) + insertMap[key] = store.NewObj(storedValue, exDurationMs, oType) } store.PutAll(insertMap) @@ -294,8 +294,7 @@ func jsonMGETHelper(store *dstore.Store, path, key string) (result interface{}, } // Check if the object is of JSON type - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return result, errWithMessage } @@ -625,11 +624,7 @@ func evalSDIFF(args []string, store *dstore.Store) []byte { return clientio.Encode([]string{}, false) } - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeSet); err != nil { - return diceerrors.NewErrWithFormattedMessage(diceerrors.WrongTypeErr) - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingSetStr); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeSet); err != nil { return diceerrors.NewErrWithFormattedMessage(diceerrors.WrongTypeErr) } @@ -656,11 +651,7 @@ func evalSDIFF(args []string, store *dstore.Store) []byte { } // If the object exists, check if it is a set object. - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeSet); err != nil { - return diceerrors.NewErrWithFormattedMessage(diceerrors.WrongTypeErr) - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingSetStr); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeSet); err != nil { return diceerrors.NewErrWithFormattedMessage(diceerrors.WrongTypeErr) } @@ -710,11 +701,7 @@ func evalSINTER(args []string, store *dstore.Store) []byte { } // If the object exists, check if it is a set object. - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeSet); err != nil { - return diceerrors.NewErrWithFormattedMessage(diceerrors.WrongTypeErr) - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingSetStr); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeSet); err != nil { return diceerrors.NewErrWithFormattedMessage(diceerrors.WrongTypeErr) } diff --git a/internal/eval/eval_test.go b/internal/eval/eval_test.go index fc6028e02..61ae149fe 100644 --- a/internal/eval/eval_test.go +++ b/internal/eval/eval_test.go @@ -133,7 +133,6 @@ func TestEval(t *testing.T) { testEvalGEOADD(t, store) testEvalGEODIST(t, store) testEvalSINTER(t, store) - testEvalOBJECTENCODING(t, store) testEvalJSONSTRAPPEND(t, store) testEvalINCR(t, store) testEvalINCRBY(t, store) @@ -288,7 +287,7 @@ func testEvalSET(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "bar" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, migratedOutput: EvalResponse{Result: "bar", Error: nil}, @@ -304,7 +303,7 @@ func testEvalSET(t *testing.T, store *dstore.Store) { value := "{\"a\":2}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, @@ -929,7 +928,7 @@ func testEvalJSONARRTRIM(t *testing.T, store *dstore.Store) { value := `{"a":2}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$", "a", "1"}, @@ -945,7 +944,7 @@ func testEvalJSONARRTRIM(t *testing.T, store *dstore.Store) { value := `[1,2,3]` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$", "0", "10"}, @@ -961,7 +960,7 @@ func testEvalJSONARRTRIM(t *testing.T, store *dstore.Store) { value := `{"a":2}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.a", "0", "6"}, @@ -977,7 +976,7 @@ func testEvalJSONARRTRIM(t *testing.T, store *dstore.Store) { value := `[1,2,3,4,5]` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$", "0", "2"}, @@ -993,7 +992,7 @@ func testEvalJSONARRTRIM(t *testing.T, store *dstore.Store) { value := `{"connection":{"wireless":true,"names":[0,1,2,3,4]},"names":[0,1,2,3,4]}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.names", "1", "3"}, @@ -1015,7 +1014,7 @@ func testEvalJSONARRTRIM(t *testing.T, store *dstore.Store) { }` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$..names", "1", "3"}, @@ -1031,7 +1030,7 @@ func testEvalJSONARRTRIM(t *testing.T, store *dstore.Store) { value := `{"connection":{"wireless":true,"names":[0,1,2,3,4]},"names":[0,1,2,3,4]}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.connection", "1", "2"}, @@ -1047,7 +1046,7 @@ func testEvalJSONARRTRIM(t *testing.T, store *dstore.Store) { value := `{"connection":{"wireless":true,"names":[0,1,2,3,4]},"names":[0,1,2,3,4]}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.names", "-3", "-1"}, @@ -1063,7 +1062,7 @@ func testEvalJSONARRTRIM(t *testing.T, store *dstore.Store) { value := `{"connection":{"wireless":true,"names":[0,1,2,3,4]},"names":[0,1,2,3,4]}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.names", "-1", "-3"}, @@ -1120,7 +1119,7 @@ func testEvalJSONARRINSERT(t *testing.T, store *dstore.Store) { value := "{\"a\":2}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"NONEXISTENT_KEY", "$.a", "0", "1"}, @@ -1136,7 +1135,7 @@ func testEvalJSONARRINSERT(t *testing.T, store *dstore.Store) { value := "{\"a\":2}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.a", "a", "1"}, @@ -1152,7 +1151,7 @@ func testEvalJSONARRINSERT(t *testing.T, store *dstore.Store) { value := "[1,2,3]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$", "4", "\"a\"", "1"}, @@ -1168,7 +1167,7 @@ func testEvalJSONARRINSERT(t *testing.T, store *dstore.Store) { value := "{\"a\":2}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.a", "0", "6"}, @@ -1184,7 +1183,7 @@ func testEvalJSONARRINSERT(t *testing.T, store *dstore.Store) { value := "[1,2]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$", "0", "6", "\"a\"", "3.14"}, @@ -1200,7 +1199,7 @@ func testEvalJSONARRINSERT(t *testing.T, store *dstore.Store) { value := `{"connection":{"wireless":true,"names":["1","2"]},"price":99.98,"names":[3,4]}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$..names", "2", "7", "8"}, @@ -1216,7 +1215,7 @@ func testEvalJSONARRINSERT(t *testing.T, store *dstore.Store) { value := `{"connection":{"wireless":true,"names":["1","2"]},"price":99.98,"names":[3,4]}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$..names", "-1", "7", "8"}, @@ -1232,7 +1231,7 @@ func testEvalJSONARRINSERT(t *testing.T, store *dstore.Store) { value := "{\"a\":[1,2,3]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.a", "0", "1", "null", "3.14", "true", "{\"a\":123}"}, @@ -1296,7 +1295,7 @@ func testEvalJSONARRLEN(t *testing.T, store *dstore.Store) { value := "{\"age\":13,\"name\":\"a\"}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -1312,7 +1311,7 @@ func testEvalJSONARRLEN(t *testing.T, store *dstore.Store) { value := "[1,2,3]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -1328,7 +1327,7 @@ func testEvalJSONARRLEN(t *testing.T, store *dstore.Store) { value := "{\"age\":13,\"high\":1.60,\"pet\":null,\"flag\":false, \"partner\":{\"name\":\"tom\"}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1346,7 +1345,7 @@ func testEvalJSONARRLEN(t *testing.T, store *dstore.Store) { "\"flag\":false, \"partner\":{\"name\":\"tom\"}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1420,7 +1419,7 @@ func testEvalJSONOBJLEN(t *testing.T, store *dstore.Store) { value := "[1,2,3]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -1436,7 +1435,7 @@ func testEvalJSONOBJLEN(t *testing.T, store *dstore.Store) { value := "{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -1452,7 +1451,7 @@ func testEvalJSONOBJLEN(t *testing.T, store *dstore.Store) { value := "{\"name\":\"John\",\"age\":30,\"pets\":null,\"languages\":[\"python\",\"golang\"],\"flag\":false}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.*"}, @@ -1468,7 +1467,7 @@ func testEvalJSONOBJLEN(t *testing.T, store *dstore.Store) { value := "{\"person\":{\"name\":\"John\",\"age\":30},\"languages\":[\"python\",\"golang\"]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.person"}, @@ -1484,7 +1483,7 @@ func testEvalJSONOBJLEN(t *testing.T, store *dstore.Store) { value := "{\"name\":\"John\",\"age\":30}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$invalid_path"}, @@ -1500,7 +1499,7 @@ func testEvalJSONOBJLEN(t *testing.T, store *dstore.Store) { value := "{\"person\":{\"name\":\"John\",\"age\":30},\"languages\":[\"python\",\"golang\"]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.person.age"}, @@ -1516,7 +1515,7 @@ func testEvalJSONOBJLEN(t *testing.T, store *dstore.Store) { value := "{\"person\":{\"name\":\"John\",\"age\":30},\"languages\":[\"python\",\"golang\"]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.person.name"}, @@ -1532,7 +1531,7 @@ func testEvalJSONOBJLEN(t *testing.T, store *dstore.Store) { value := "{\"person\":{\"name\":\"John\",\"age\":30},\"languages\":[\"python\",\"golang\"]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.languages"}, @@ -1625,7 +1624,7 @@ func testEvalJSONDEL(t *testing.T, store *dstore.Store) { "\"flag\":false, \"partner\":{\"name\":\"tom\",\"language\":[\"rust\"]}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -1642,7 +1641,7 @@ func testEvalJSONDEL(t *testing.T, store *dstore.Store) { "\"flag\":false, \"partner\":{\"name\":\"tom\",\"language\":[\"rust\"]}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1660,7 +1659,7 @@ func testEvalJSONDEL(t *testing.T, store *dstore.Store) { "\"flag\":false, \"partner\":{\"name\":\"tom\",\"language\":[\"rust\"]}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1702,7 +1701,7 @@ func testEvalJSONFORGET(t *testing.T, store *dstore.Store) { "\"flag\":false, \"partner\":{\"name\":\"tom\",\"language\":[\"rust\"]}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -1719,7 +1718,7 @@ func testEvalJSONFORGET(t *testing.T, store *dstore.Store) { "\"flag\":false, \"partner\":{\"name\":\"tom\",\"language\":[\"rust\"]}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1737,7 +1736,7 @@ func testEvalJSONFORGET(t *testing.T, store *dstore.Store) { "\"flag\":false, \"partner\":{\"name\":\"tom\",\"language\":[\"rust\"]}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1788,7 +1787,7 @@ func testEvalJSONCLEAR(t *testing.T, store *dstore.Store) { "\"partner\":{\"name\":\"tom\",\"language\":[\"rust\"]}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -1804,7 +1803,7 @@ func testEvalJSONCLEAR(t *testing.T, store *dstore.Store) { value := "{\"array\":[1,2,3,\"s\",null]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1821,7 +1820,7 @@ func testEvalJSONCLEAR(t *testing.T, store *dstore.Store) { value := "{\"a\":\"test\"}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1838,7 +1837,7 @@ func testEvalJSONCLEAR(t *testing.T, store *dstore.Store) { value := "{\"age\":13}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1855,7 +1854,7 @@ func testEvalJSONCLEAR(t *testing.T, store *dstore.Store) { value := "{\"price\":3.14}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1872,7 +1871,7 @@ func testEvalJSONCLEAR(t *testing.T, store *dstore.Store) { value := "{\"flag\":false}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.flag"}, @@ -1889,7 +1888,7 @@ func testEvalJSONCLEAR(t *testing.T, store *dstore.Store) { "\"partner\":{\"name\":\"tom\",\"language\":[\"rust\"]}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.*"}, @@ -1955,7 +1954,7 @@ func testEvalJSONTYPE(t *testing.T, store *dstore.Store) { value := "{\"language\":[\"java\",\"go\",\"python\"]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1971,7 +1970,7 @@ func testEvalJSONTYPE(t *testing.T, store *dstore.Store) { value := "{\"language\":[\"java\",\"go\",\"python\"]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -1987,7 +1986,7 @@ func testEvalJSONTYPE(t *testing.T, store *dstore.Store) { value := "{\"a\":\"test\"}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -2003,7 +2002,7 @@ func testEvalJSONTYPE(t *testing.T, store *dstore.Store) { value := "{\"flag\":true}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -2019,7 +2018,7 @@ func testEvalJSONTYPE(t *testing.T, store *dstore.Store) { value := "{\"price\":3}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -2035,7 +2034,7 @@ func testEvalJSONTYPE(t *testing.T, store *dstore.Store) { value := "{\"price\":3.14}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -2051,7 +2050,7 @@ func testEvalJSONTYPE(t *testing.T, store *dstore.Store) { value := "{\"name\":\"tom\",\"partner\":{\"name\":\"jerry\"}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -2114,7 +2113,7 @@ func testEvalJSONGET(t *testing.T, store *dstore.Store) { value := "{\"a\":2}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -2231,7 +2230,7 @@ func testEvalJSONNUMMULTBY(t *testing.T, store *dstore.Store) { value := "{\"a\":10,\"b\":[{\"a\":2}, {\"a\":5}, {\"a\":\"c\"}]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"doc", "$.a", "qwe"}, @@ -2247,7 +2246,7 @@ func testEvalJSONNUMMULTBY(t *testing.T, store *dstore.Store) { value := "{\"a\": \"b\",\"b\":[{\"a\":2}, {\"a\":5}, {\"a\":\"c\"}]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"doc", "$.a", "2"}, @@ -2263,7 +2262,7 @@ func testEvalJSONNUMMULTBY(t *testing.T, store *dstore.Store) { value := "{\"a\": \"b\",\"b\":[{\"a\":2}, {\"a\":5}, {\"a\":\"c\"}]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"doc", "$..a", "2"}, @@ -2279,7 +2278,7 @@ func testEvalJSONNUMMULTBY(t *testing.T, store *dstore.Store) { value := "{\"a\":10,\"b\":[{\"a\":2}, {\"a\":5}, {\"a\":\"c\"}]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"doc", "$.a", "2"}, @@ -2295,7 +2294,7 @@ func testEvalJSONNUMMULTBY(t *testing.T, store *dstore.Store) { value := "{\"a\":10,\"b\":[{\"a\":2}, {\"a\":5}, {\"a\":\"c\"}]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"doc", "$..fe", "2"}, @@ -2316,7 +2315,7 @@ func testEvalJSONARRAPPEND(t *testing.T, store *dstore.Store) { value := "{\"a\":2}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"array", "$.a", "6"}, @@ -2332,7 +2331,7 @@ func testEvalJSONARRAPPEND(t *testing.T, store *dstore.Store) { value := "{\"a\":[1,2]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"array", "$.a", "6"}, @@ -2348,7 +2347,7 @@ func testEvalJSONARRAPPEND(t *testing.T, store *dstore.Store) { value := "{\"a\":[1,2]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"array", "$.a", "6", "7", "8"}, @@ -2364,7 +2363,7 @@ func testEvalJSONARRAPPEND(t *testing.T, store *dstore.Store) { value := "{\"b\":[\"b\",\"c\"]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"array", "$.b", `"d"`}, @@ -2380,7 +2379,7 @@ func testEvalJSONARRAPPEND(t *testing.T, store *dstore.Store) { value := "{\"a\":[[1,2]]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"array", "$.a", "[1,2,3]"}, @@ -2396,7 +2395,7 @@ func testEvalJSONARRAPPEND(t *testing.T, store *dstore.Store) { value := "{\"a\":[{\"b\": 1}]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"array", "$.a", "{\"c\": 3}"}, @@ -2412,7 +2411,7 @@ func testEvalJSONARRAPPEND(t *testing.T, store *dstore.Store) { value := "{\"a\":[1,2],\"b\":{\"a\":[10]}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"array", "$..a", "6"}, @@ -2428,7 +2427,7 @@ func testEvalJSONARRAPPEND(t *testing.T, store *dstore.Store) { value := "[1,2,3]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"array", "$", "6"}, @@ -2444,7 +2443,7 @@ func testEvalJSONARRAPPEND(t *testing.T, store *dstore.Store) { value := "{\"a\":[1,2]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"array", "$.a", `"blue"`}, @@ -2519,7 +2518,7 @@ func testEvalJSONTOGGLE(t *testing.T, store *dstore.Store) { if err != nil { fmt.Printf("Debug: Error unmarshaling JSON: %v\n", err) } - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", ".active"}, @@ -2538,7 +2537,7 @@ func testEvalJSONTOGGLE(t *testing.T, store *dstore.Store) { if err != nil { fmt.Printf("Debug: Error unmarshaling JSON: %v\n", err) } - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", ".active"}, @@ -2572,7 +2571,7 @@ func testEvalJSONTOGGLE(t *testing.T, store *dstore.Store) { value := `{"isSimple":true,"nested":{"isSimple":false}}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"NESTED_KEY", "$..isSimple"}, @@ -2588,7 +2587,7 @@ func testEvalJSONTOGGLE(t *testing.T, store *dstore.Store) { value := `{"field": true, "nested": {"field": false, "nested": {"field": true}}}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"DEEP_NESTED_KEY", "$..field"}, @@ -2996,11 +2995,11 @@ func testEvalPFADD(t *testing.T, store *dstore.Store) { name: "PFADD Incorrect type provided", setup: func() { key, value := "EXISTING_KEY", "VALUE" - oType, oEnc := deduceTypeEncoding(value) + oType := deduceType(value) var exDurationMs int64 = -1 keepttl := false - store.Put(key, store.NewObj(value, exDurationMs, oType, oEnc), dstore.WithKeepTTL(keepttl)) + store.Put(key, store.NewObj(value, exDurationMs, oType), dstore.WithKeepTTL(keepttl)) }, input: []string{"EXISTING_KEY", "1"}, output: []byte("-WRONGTYPE Key is not a valid HyperLogLog string value"), @@ -3213,7 +3212,7 @@ func testEvalHGET(t *testing.T, store *dstore.Store) { newMap[field] = "mock_field_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3234,7 +3233,7 @@ func testEvalHGET(t *testing.T, store *dstore.Store) { newMap[field] = "mock_field_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3276,7 +3275,7 @@ func testEvalHGETALL(t *testing.T, store *dstore.Store) { newMap := make(HashMap) // Empty hash map obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3298,7 +3297,7 @@ func testEvalHGETALL(t *testing.T, store *dstore.Store) { newMap["field3"] = "value3" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3350,7 +3349,7 @@ func testEvalHMGET(t *testing.T, store *dstore.Store) { newMap[field] = "mock_field_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3371,7 +3370,7 @@ func testEvalHMGET(t *testing.T, store *dstore.Store) { newMap[field] = "mock_field_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3392,7 +3391,7 @@ func testEvalHMGET(t *testing.T, store *dstore.Store) { "field2": "value2", } obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3433,7 +3432,7 @@ func testEvalHVALS(t *testing.T, store *dstore.Store) { newMap[field] = "mock_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3502,7 +3501,7 @@ func testEvalHSTRLEN(t *testing.T, store *dstore.Store) { newMap[field] = "mock_field_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3520,7 +3519,7 @@ func testEvalHSTRLEN(t *testing.T, store *dstore.Store) { newMap[field] = "HelloWorld" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3564,7 +3563,7 @@ func testEvalHEXISTS(t *testing.T, store *dstore.Store) { newMap[field] = "mock_field_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3583,7 +3582,7 @@ func testEvalHEXISTS(t *testing.T, store *dstore.Store) { newMap[field] = "HelloWorld" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -3787,7 +3786,7 @@ func testEvalJSONSTRLEN(t *testing.T, store *dstore.Store) { value := "{\"name\":\"Bhima\",\"age\":10}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -3803,7 +3802,7 @@ func testEvalJSONSTRLEN(t *testing.T, store *dstore.Store) { value := "10.9" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -3819,7 +3818,7 @@ func testEvalJSONSTRLEN(t *testing.T, store *dstore.Store) { value := "10" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -3835,7 +3834,7 @@ func testEvalJSONSTRLEN(t *testing.T, store *dstore.Store) { value := "[\"age\", \"name\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -3851,7 +3850,7 @@ func testEvalJSONSTRLEN(t *testing.T, store *dstore.Store) { value := "true" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -3867,7 +3866,7 @@ func testEvalJSONSTRLEN(t *testing.T, store *dstore.Store) { value := `"hello"` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -3883,7 +3882,7 @@ func testEvalJSONSTRLEN(t *testing.T, store *dstore.Store) { value := `{"partner":{"name":"tom","language":["rust"]}}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -3900,7 +3899,7 @@ func testEvalJSONSTRLEN(t *testing.T, store *dstore.Store) { value := `{"partner":{"name":21,"language":["rust"]}}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, @@ -4176,7 +4175,7 @@ func testEvalJSONNUMINCRBY(t *testing.T, store *dstore.Store) { value := "{\"a\": 2}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"number", "$.a", "3"}, @@ -4193,7 +4192,7 @@ func testEvalJSONNUMINCRBY(t *testing.T, store *dstore.Store) { value := "{\"a\": 2.5}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"number", "$.a", "1.5"}, @@ -4210,7 +4209,7 @@ func testEvalJSONNUMINCRBY(t *testing.T, store *dstore.Store) { value := "{\"a\": 2, \"b\": 10, \"c\": [15, {\"d\": 20}]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"number", "$..*", "5"}, @@ -4240,7 +4239,7 @@ func testEvalJSONNUMINCRBY(t *testing.T, store *dstore.Store) { value := "{\"a\": [1, 2, 3]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"number", "$.a[1]", "5"}, @@ -4256,7 +4255,7 @@ func testEvalJSONNUMINCRBY(t *testing.T, store *dstore.Store) { value := "{\"a\": 2}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"number", "$.b", "3"}, @@ -4272,7 +4271,7 @@ func testEvalJSONNUMINCRBY(t *testing.T, store *dstore.Store) { value := "{\"a\": 5, \"b\": \"not a number\", \"c\": [1, 2]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"number", "$..*", "2"}, @@ -4319,7 +4318,7 @@ func testEvalJSONNUMINCRBY(t *testing.T, store *dstore.Store) { value := "{\"a\": {\"b\": {\"c\": 10}}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"number", "$..c", "5"}, @@ -4471,7 +4470,7 @@ func testEvalHSET(t *testing.T, store *dstore.Store) { newMap[field] = "mock_field_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -4493,7 +4492,7 @@ func testEvalHSET(t *testing.T, store *dstore.Store) { newMap[field] = mockValue obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -4574,7 +4573,7 @@ func testEvalHMSET(t *testing.T, store *dstore.Store) { newMap[field] = "mock_field_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -4596,7 +4595,7 @@ func testEvalHMSET(t *testing.T, store *dstore.Store) { newMap[field] = mockValue obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -4650,7 +4649,7 @@ func testEvalHKEYS(t *testing.T, store *dstore.Store) { newMap[field1] = "HelloWorld" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -4827,7 +4826,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "{\"a\": 1}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY"}, @@ -4840,7 +4839,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "{\"a\": 1}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$"}, @@ -4853,7 +4852,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "{\"a\": 1}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "INVALID_PATH"}, @@ -4866,7 +4865,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "{\"a\": 1, \"b\": 2}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$.a"}, @@ -4881,7 +4880,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "{\"a\": 1, \"b\": \"dice\"}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$.a", "$.b"}, @@ -4894,7 +4893,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[\"roll\", \"the\", \"dices\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[1]"}, @@ -4907,7 +4906,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[\"roll\", \"the\", \"dices\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[1,2]"}, @@ -4920,7 +4919,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[\"roll\", \"the\", \"dices\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[4]"}, @@ -4933,7 +4932,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[\"roll\", \"the\", \"dices\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[1,2,4]"}, @@ -4946,7 +4945,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[\"roll\", \"the\", \"dices\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[-1]"}, @@ -4959,7 +4958,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[\"roll\", \"the\", \"dices\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[-1,-2]"}, @@ -4972,7 +4971,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[\"roll\", \"the\", \"dices\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[-4]"}, @@ -4985,7 +4984,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[\"roll\", \"the\", \"dices\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[*]"}, @@ -4998,7 +4997,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[\"roll\", \"the\", \"dices\"]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[:]"}, @@ -5011,7 +5010,7 @@ func testEvalDebug(t *testing.T, store *dstore.Store) { value := "[2, 3.5, true, null, \"dice\", {}, [], {\"a\": 1, \"b\": 2}, [7, 8, 0]]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MEMORY", "EXISTING_KEY", "$[:]"}, @@ -5105,7 +5104,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "[]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -5121,7 +5120,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "{\"a\": 1, \"b\": []}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY", "$.b"}, @@ -5137,7 +5136,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "{\"a\": 1, \"b\": []}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY", "$.*"}, @@ -5153,7 +5152,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "[0, 1, 2, 3, 4, 5]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -5169,7 +5168,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "[0, 1, 2, 3, 4, 5]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY", "$", "2"}, @@ -5185,7 +5184,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "[0, 1, 2, 3, 4, 5]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY", "$", "10"}, @@ -5201,7 +5200,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "[0, 1, 2, 3, 4, 5]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY", "$", "-2"}, @@ -5217,7 +5216,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "[0, 1, 2, 3, 4, 5]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY", "$", "-10"}, @@ -5233,7 +5232,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "[0, 1, 2, 3, 4, 5]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY", "$", "2"}, @@ -5256,7 +5255,7 @@ func testEvalJSONARRPOP(t *testing.T, store *dstore.Store) { value := "{\"a\": 2, \"b\": [0, 1, 2, 3, 4, 5]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY", "$.b", "2"}, @@ -5332,7 +5331,7 @@ func testEvalTYPE(t *testing.T, store *dstore.Store) { "TYPE key exists and is of type String": { name: "TYPE key exists and is of type String", setup: func() { - store.Put("string_key", store.NewObj("value", -1, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("string_key", store.NewObj("value", -1, object.ObjTypeString)) }, input: []string{"string_key"}, migratedOutput: EvalResponse{ @@ -5343,7 +5342,7 @@ func testEvalTYPE(t *testing.T, store *dstore.Store) { "TYPE key exists and is of type List": { name: "TYPE key exists and is of type List", setup: func() { - store.Put("list_key", store.NewObj([]byte("value"), -1, object.ObjTypeByteList, object.ObjEncodingRaw)) + evalLPUSH([]string{"list_key", "value"}, store) }, input: []string{"list_key"}, migratedOutput: EvalResponse{ @@ -5354,7 +5353,7 @@ func testEvalTYPE(t *testing.T, store *dstore.Store) { "TYPE key exists and is of type Set": { name: "TYPE key exists and is of type Set", setup: func() { - store.Put("set_key", store.NewObj([]byte("value"), -1, object.ObjTypeSet, object.ObjEncodingRaw)) + store.Put("set_key", store.NewObj([]byte("value"), -1, object.ObjTypeSet)) }, input: []string{"set_key"}, migratedOutput: EvalResponse{ @@ -5365,7 +5364,7 @@ func testEvalTYPE(t *testing.T, store *dstore.Store) { "TYPE key exists and is of type Hash": { name: "TYPE key exists and is of type Hash", setup: func() { - store.Put("hash_key", store.NewObj([]byte("value"), -1, object.ObjTypeHashMap, object.ObjEncodingRaw)) + store.Put("hash_key", store.NewObj([]byte("value"), -1, object.ObjTypeHashMap)) }, input: []string{"hash_key"}, migratedOutput: EvalResponse{ @@ -5383,16 +5382,16 @@ func BenchmarkEvalTYPE(b *testing.B) { // Define different types of objects to benchmark objectTypes := map[string]func(){ "String": func() { - store.Put("string_key", store.NewObj("value", -1, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("string_key", store.NewObj("value", -1, object.ObjTypeString)) }, "List": func() { - store.Put("list_key", store.NewObj([]byte("value"), -1, object.ObjTypeByteList, object.ObjEncodingRaw)) + store.Put("list_key", store.NewObj([]byte("value"), -1, object.ObjTypeDequeue)) }, "Set": func() { - store.Put("set_key", store.NewObj([]byte("value"), -1, object.ObjTypeSet, object.ObjEncodingRaw)) + store.Put("set_key", store.NewObj([]byte("value"), -1, object.ObjTypeSet)) }, "Hash": func() { - store.Put("hash_key", store.NewObj([]byte("value"), -1, object.ObjTypeHashMap, object.ObjEncodingRaw)) + store.Put("hash_key", store.NewObj([]byte("value"), -1, object.ObjTypeHashMap)) }, } @@ -5609,7 +5608,7 @@ func testEvalJSONOBJKEYS(t *testing.T, store *dstore.Store) { value := "[1]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY"}, @@ -5625,7 +5624,7 @@ func testEvalJSONOBJKEYS(t *testing.T, store *dstore.Store) { value := `{"name":"John","age":30,"pets":null,"languages":["python","golang"],"flag":false}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.*"}, @@ -5641,7 +5640,7 @@ func testEvalJSONOBJKEYS(t *testing.T, store *dstore.Store) { value := `{"person":{"name":"John","age":30},"languages":["python","golang"]}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.person.age"}, @@ -5657,7 +5656,7 @@ func testEvalJSONOBJKEYS(t *testing.T, store *dstore.Store) { value := `{"person":{"name":"John","age":30},"languages":["python","golang"]}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.person.name"}, @@ -5673,7 +5672,7 @@ func testEvalJSONOBJKEYS(t *testing.T, store *dstore.Store) { value := `{"person":{"name":"John","age":30},"languages":["python","golang"]}` var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"EXISTING_KEY", "$.languages"}, @@ -5742,10 +5741,10 @@ func BenchmarkEvalJSONOBJKEYS(b *testing.B) { func testEvalGETRANGE(t *testing.T, store *dstore.Store) { setupForStringValue := func() { - store.Put("STRING_KEY", store.NewObj("Hello World", maxExDuration, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("STRING_KEY", store.NewObj("Hello World", maxExDuration, object.ObjTypeString)) } setupForIntegerValue := func() { - store.Put("INTEGER_KEY", store.NewObj("1234", maxExDuration, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("INTEGER_KEY", store.NewObj("1234", maxExDuration, object.ObjTypeString)) } tests := map[string]evalTestCase{ "GETRANGE against non-existing key": { @@ -5944,7 +5943,7 @@ func testEvalGETRANGE(t *testing.T, store *dstore.Store) { "GETRANGE against byte array with valid range: 0 4": { setup: func() { key := "BYTEARRAY_KEY" - store.Put(key, store.NewObj(&ByteArray{data: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64}}, maxExDuration, object.ObjTypeByteArray, object.ObjEncodingByteArray)) + store.Put(key, store.NewObj(&ByteArray{data: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64}}, maxExDuration, object.ObjTypeByteArray)) }, input: []string{"BYTEARRAY_KEY", "0", "4"}, migratedOutput: EvalResponse{Result: "hello", Error: nil}, @@ -5952,7 +5951,7 @@ func testEvalGETRANGE(t *testing.T, store *dstore.Store) { "GETRANGE against byte array with valid range: 6 -1": { setup: func() { key := "BYTEARRAY_KEY" - store.Put(key, store.NewObj(&ByteArray{data: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64}}, maxExDuration, object.ObjTypeByteArray, object.ObjEncodingByteArray)) + store.Put(key, store.NewObj(&ByteArray{data: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64}}, maxExDuration, object.ObjTypeByteArray)) }, input: []string{"BYTEARRAY_KEY", "6", "-1"}, migratedOutput: EvalResponse{Result: "world", Error: nil}, @@ -5960,7 +5959,7 @@ func testEvalGETRANGE(t *testing.T, store *dstore.Store) { "GETRANGE against byte array with invalid range: 20 30": { setup: func() { key := "BYTEARRAY_KEY" - store.Put(key, store.NewObj(&ByteArray{data: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64}}, maxExDuration, object.ObjTypeByteArray, object.ObjEncodingByteArray)) + store.Put(key, store.NewObj(&ByteArray{data: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64}}, maxExDuration, object.ObjTypeByteArray)) }, input: []string{"BYTEARRAY_KEY", "20", "30"}, migratedOutput: EvalResponse{Result: "", Error: nil}, @@ -5972,7 +5971,7 @@ func testEvalGETRANGE(t *testing.T, store *dstore.Store) { func BenchmarkEvalGETRANGE(b *testing.B) { store := dstore.NewStore(nil, nil, nil) - store.Put("BENCHMARK_KEY", store.NewObj("Hello World", maxExDuration, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("BENCHMARK_KEY", store.NewObj("Hello World", maxExDuration, object.ObjTypeString)) inputs := []struct { start string @@ -6060,7 +6059,7 @@ func testEvalHSETNX(t *testing.T, store *dstore.Store) { newMap[field] = "mock_field_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6081,7 +6080,7 @@ func testEvalHSETNX(t *testing.T, store *dstore.Store) { newMap[field] = "existing_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6149,7 +6148,7 @@ func testEvalHINCRBY(t *testing.T, store *dstore.Store) { h := make(HashMap) h[field] = "10" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6175,7 +6174,7 @@ func testEvalHINCRBY(t *testing.T, store *dstore.Store) { newMap := make(HashMap) newMap[field] = "new_value" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6193,7 +6192,7 @@ func testEvalHINCRBY(t *testing.T, store *dstore.Store) { h[field] = " 10 " obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6215,7 +6214,7 @@ func testEvalHINCRBY(t *testing.T, store *dstore.Store) { h[field] = "-10" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6232,7 +6231,7 @@ func testEvalHINCRBY(t *testing.T, store *dstore.Store) { h[field] = fmt.Sprintf("%v", math.MaxInt64) obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6249,7 +6248,7 @@ func testEvalHINCRBY(t *testing.T, store *dstore.Store) { h[field] = fmt.Sprintf("%v", math.MinInt64) obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6404,7 +6403,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "2.1" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingRaw) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", "0.1"}, @@ -6415,7 +6414,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "2" - obj := store.NewObj(value, -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(value, -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"key", "0.1"}, @@ -6426,7 +6425,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "2" - obj := store.NewObj(value, -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(value, -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"key", "-0.1"}, @@ -6437,7 +6436,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "1" - obj := store.NewObj(value, -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(value, -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"key", "1e-2"}, @@ -6448,7 +6447,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "1e2" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", "1e-1"}, @@ -6459,7 +6458,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "0.1" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", "-0.1"}, @@ -6470,7 +6469,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := " 2 " - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", "0.1"}, @@ -6481,7 +6480,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "string" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", "0.1"}, @@ -6492,7 +6491,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "2.0" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", "a"}, @@ -6503,7 +6502,7 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "1e308" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", "1e308"}, @@ -6539,8 +6538,8 @@ func testEvalINCRBYFLOAT(t *testing.T, store *dstore.Store) { func BenchmarkEvalINCRBYFLOAT(b *testing.B) { store := dstore.NewStore(nil, nil, nil) - store.Put("key1", store.NewObj("1", maxExDuration, object.ObjTypeString, object.ObjEncodingEmbStr)) - store.Put("key2", store.NewObj("1.2", maxExDuration, object.ObjTypeString, object.ObjEncodingEmbStr)) + store.Put("key1", store.NewObj("1", maxExDuration, object.ObjTypeString)) + store.Put("key2", store.NewObj("1.2", maxExDuration, object.ObjTypeString)) inputs := []struct { key string @@ -6585,7 +6584,7 @@ func testEvalHRANDFIELD(t *testing.T, store *dstore.Store) { newMap["field2"] = "Value2" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6614,7 +6613,7 @@ func testEvalHRANDFIELD(t *testing.T, store *dstore.Store) { newMap["field3"] = "value3" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6650,7 +6649,7 @@ func testEvalHRANDFIELD(t *testing.T, store *dstore.Store) { newMap["field3"] = "value3" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: newMap, LastAccessedAt: uint32(time.Now().Unix()), } @@ -6706,7 +6705,7 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "val" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingRaw) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", "val"}, @@ -6720,8 +6719,8 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { migratedOutput: EvalResponse{Result: 3, Error: nil}, validator: func(output []byte) { obj := store.Get("key") - _, enc := object.ExtractTypeEncoding(obj) - if enc != object.ObjEncodingInt { + oType := object.ExtractType(obj) + if oType != object.ObjTypeInt { t.Errorf("unexpected encoding") } }, @@ -6731,7 +6730,7 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { key := "key" value := "123" storedValue, _ := strconv.ParseInt(value, 10, 64) - obj := store.NewObj(storedValue, -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(storedValue, -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"key", "val"}, @@ -6748,7 +6747,7 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingRaw) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", ""}, @@ -6758,7 +6757,7 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { setup: func() { key := "key" value := "val" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingRaw) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"key", ""}, @@ -6768,15 +6767,15 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { setup: func() { store.Del("key") storedValue, _ := strconv.ParseInt("1", 10, 64) - obj := store.NewObj(storedValue, -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(storedValue, -1, object.ObjTypeInt) store.Put("key", obj) }, input: []string{"key", "2"}, migratedOutput: EvalResponse{Result: 2, Error: nil}, validator: func(output []byte) { obj := store.Get("key") - _, enc := object.ExtractTypeEncoding(obj) - if enc != object.ObjEncodingRaw { + oType := object.ExtractType(obj) + if oType != object.ObjTypeString { t.Errorf("unexpected encoding") } }, @@ -6786,7 +6785,7 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { key := "listKey" value := "val" // Create a new list object - obj := store.NewObj(NewDeque(), -1, object.ObjTypeByteList, object.ObjEncodingDeque) + obj := store.NewObj(NewDeque(), -1, object.ObjTypeDequeue) store.Put(key, obj) obj.Value.(*Deque).LPush(value) }, @@ -6801,7 +6800,7 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { "existingVal": {}, "anotherVal": {}, } - obj := store.NewObj(initialValues, -1, object.ObjTypeSet, object.ObjEncodingSetStr) + obj := store.NewObj(initialValues, -1, object.ObjTypeSet) store.Put(key, obj) }, input: []string{"setKey", "val"}, @@ -6815,7 +6814,7 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { "field1": "value1", "field2": "value2", } - obj := store.NewObj(initialValues, -1, object.ObjTypeHashMap, object.ObjEncodingHashMap) + obj := store.NewObj(initialValues, -1, object.ObjTypeHashMap) store.Put(key, obj) }, input: []string{"hashKey", "val"}, @@ -6832,7 +6831,7 @@ func testEvalAPPEND(t *testing.T, store *dstore.Store) { initialByteArray.SetBit(10, true) // Set the eleventh bit to 1 initialByteArray.SetBit(11, true) // Set the twelfth bit to 1 initialByteArray.SetBit(14, true) // Set the fifteenth bit to 1 - obj := store.NewObj(initialByteArray, -1, object.ObjTypeByteArray, object.ObjEncodingByteArray) + obj := store.NewObj(initialByteArray, -1, object.ObjTypeByteArray) store.Put(key, obj) }, input: []string{"bitKey", "1"}, @@ -6875,7 +6874,7 @@ func testEvalJSONRESP(t *testing.T, store *dstore.Store) { value := "\"Roll the Dice\"" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -6887,7 +6886,7 @@ func testEvalJSONRESP(t *testing.T, store *dstore.Store) { value := "10" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -6899,7 +6898,7 @@ func testEvalJSONRESP(t *testing.T, store *dstore.Store) { value := "true" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -6910,7 +6909,7 @@ func testEvalJSONRESP(t *testing.T, store *dstore.Store) { key := "MOCK_KEY" var rootData interface{} _ = sonic.Unmarshal([]byte(nil), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -6922,7 +6921,7 @@ func testEvalJSONRESP(t *testing.T, store *dstore.Store) { value := "[]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -6934,7 +6933,7 @@ func testEvalJSONRESP(t *testing.T, store *dstore.Store) { value := "{}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -6946,7 +6945,7 @@ func testEvalJSONRESP(t *testing.T, store *dstore.Store) { value := "[\"dice\", 10, 10.5, true, null]" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -6958,7 +6957,7 @@ func testEvalJSONRESP(t *testing.T, store *dstore.Store) { value := "{\"b\": [\"dice\", 10, 10.5, true, null]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY"}, @@ -6970,7 +6969,7 @@ func testEvalJSONRESP(t *testing.T, store *dstore.Store) { value := "{\"b\": [\"dice\", 10, 10.5, true, null]}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"MOCK_KEY", "$.b"}, @@ -7304,7 +7303,7 @@ func testEvalZADD(t *testing.T, store *dstore.Store) { }, "ZADD to a key of wrong type": { setup: func() { - store.Put("mywrongtypekey", store.NewObj("string_value", -1, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("mywrongtypekey", store.NewObj("string_value", -1, object.ObjTypeString)) }, input: []string{"mywrongtypekey", "1", "member1"}, migratedOutput: EvalResponse{ @@ -7328,7 +7327,7 @@ func testEvalZRANGE(t *testing.T, store *dstore.Store) { }, "ZRANGE with wrong type key": { setup: func() { - store.Put("mystring", store.NewObj("string_value", -1, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("mystring", store.NewObj("string_value", -1, object.ObjTypeString)) }, input: []string{"mystring", "0", "-1"}, migratedOutput: EvalResponse{ @@ -7452,7 +7451,7 @@ func testEvalZPOPMIN(t *testing.T, store *dstore.Store) { }, "ZPOPMIN with wrong type of key with/without count argument": { setup: func() { - store.Put("mystring", store.NewObj("string_value", -1, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("mystring", store.NewObj("string_value", -1, object.ObjTypeString)) }, input: []string{"mystring", "1"}, migratedOutput: EvalResponse{ @@ -7522,7 +7521,7 @@ func testEvalZPOPMIN(t *testing.T, store *dstore.Store) { }, "ZPOPMIN on empty sorted set": { setup: func() { - store.Put("myzset", store.NewObj(sortedset.New(), -1, object.ObjTypeSortedSet, object.ObjEncodingBTree)) // Ensure the set exists but is empty + store.Put("myzset", store.NewObj(sortedset.New(), -1, object.ObjTypeSortedSet)) // Ensure the set exists but is empty }, input: []string{"myzset"}, migratedOutput: EvalResponse{ @@ -7694,7 +7693,7 @@ func testEvalZREM(t *testing.T, store *dstore.Store) { }, "ZREM with wrong type key": { setup: func() { - store.Put("string_key", store.NewObj("string_value", -1, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("string_key", store.NewObj("string_value", -1, object.ObjTypeString)) }, input: []string{"string_key", "field"}, migratedOutput: EvalResponse{ @@ -7787,7 +7786,7 @@ func testEvalZCARD(t *testing.T, store *dstore.Store) { }, "ZCARD with wrong type key": { setup: func() { - store.Put("string_key", store.NewObj("string_value", -1, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("string_key", store.NewObj("string_value", -1, object.ObjTypeString)) }, input: []string{"string_key"}, migratedOutput: EvalResponse{ @@ -7899,7 +7898,7 @@ func testEvalHINCRBYFLOAT(t *testing.T, store *dstore.Store) { key := "key" h := make(HashMap) obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -7915,7 +7914,7 @@ func testEvalHINCRBYFLOAT(t *testing.T, store *dstore.Store) { h := make(HashMap) h[field] = "2.1" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -7931,7 +7930,7 @@ func testEvalHINCRBYFLOAT(t *testing.T, store *dstore.Store) { h := make(HashMap) h[field] = "2" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -7947,7 +7946,7 @@ func testEvalHINCRBYFLOAT(t *testing.T, store *dstore.Store) { h := make(HashMap) h[field] = "2.0" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -7963,7 +7962,7 @@ func testEvalHINCRBYFLOAT(t *testing.T, store *dstore.Store) { h := make(HashMap) h[field] = "2.0" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -7980,7 +7979,7 @@ func testEvalHINCRBYFLOAT(t *testing.T, store *dstore.Store) { h := make(HashMap) h[field] = "non_numeric" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -7996,7 +7995,7 @@ func testEvalHINCRBYFLOAT(t *testing.T, store *dstore.Store) { h := make(HashMap) h[field] = "1e308" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -8012,7 +8011,7 @@ func testEvalHINCRBYFLOAT(t *testing.T, store *dstore.Store) { h := make(HashMap) h[field] = "1e2" obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: h, LastAccessedAt: uint32(time.Now().Unix()), } @@ -8030,8 +8029,8 @@ func BenchmarkEvalHINCRBYFLOAT(b *testing.B) { store := dstore.NewStore(nil, nil, nil) // Setting initial fields with some values - store.Put("key1", store.NewObj(HashMap{"field1": "1.0", "field2": "1.2"}, maxExDuration, object.ObjTypeHashMap, object.ObjEncodingHashMap)) - store.Put("key2", store.NewObj(HashMap{"field1": "0.1"}, maxExDuration, object.ObjTypeHashMap, object.ObjEncodingHashMap)) + store.Put("key1", store.NewObj(HashMap{"field1": "1.0", "field2": "1.2"}, maxExDuration, object.ObjTypeHashMap)) + store.Put("key2", store.NewObj(HashMap{"field1": "0.1"}, maxExDuration, object.ObjTypeHashMap)) inputs := []struct { key string @@ -8085,7 +8084,7 @@ func testEvalDUMP(t *testing.T, store *dstore.Store) { setup: func() { key := "user" value := "hello" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingRaw) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"user"}, @@ -8103,7 +8102,7 @@ func testEvalDUMP(t *testing.T, store *dstore.Store) { setup: func() { key := "INTEGER_KEY" value := int64(10) - obj := store.NewObj(value, -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(value, -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"INTEGER_KEY"}, @@ -8122,7 +8121,7 @@ func testEvalDUMP(t *testing.T, store *dstore.Store) { setup: func() { key := "EXPIRED_KEY" value := "This will expire" - obj := store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingRaw) + obj := store.NewObj(value, -1, object.ObjTypeString) store.Put(key, obj) var exDurationMs int64 = -1 store.SetExpiry(obj, exDurationMs) @@ -8266,7 +8265,7 @@ func testEvalGEOADD(t *testing.T, store *dstore.Store) { }, "GEOADD to a key of wrong type": { setup: func() { - store.Put("mygeo", store.NewObj("string_value", -1, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("mygeo", store.NewObj("string_value", -1, object.ObjTypeString)) }, input: []string{"mygeo", "-74.0060", "40.7128", "NewYork"}, migratedOutput: EvalResponse{ @@ -8369,7 +8368,7 @@ func testEvalSINTER(t *testing.T, store *dstore.Store) { "intersection with wrong type": { setup: func() { evalSADD([]string{"set1", "a", "b", "c"}, store) - store.Put("string", &object.Obj{Value: "string", TypeEncoding: object.ObjTypeString}) + store.Put("string", &object.Obj{Value: "string", Type: object.ObjTypeString}) }, input: []string{"set1", "string"}, output: []byte("-WRONGTYPE Operation against a key holding the wrong kind of value\r\n"), @@ -8383,55 +8382,6 @@ func testEvalSINTER(t *testing.T, store *dstore.Store) { runEvalTests(t, tests, evalSINTER, store) } -func testEvalOBJECTENCODING(t *testing.T, store *dstore.Store) { - tests := map[string]evalTestCase{ - "nil value": { - setup: func() {}, - input: nil, - migratedOutput: EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongArgumentCount("OBJECT"), - }, - }, - "empty array": { - setup: func() {}, - input: []string{}, - migratedOutput: EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongArgumentCount("OBJECT"), - }, - }, - "object with invalid subcommand": { - setup: func() {}, - input: []string{"TESTSUBCOMMAND", "key"}, - migratedOutput: EvalResponse{ - Result: nil, - Error: diceerrors.ErrSyntax, - }, - }, - "key does not exist": { - setup: func() {}, - input: []string{"ENCODING", "NONEXISTENT_KEY"}, - migratedOutput: EvalResponse{ - Result: clientio.NIL, - Error: nil, - }, - }, - "key exists": { - setup: func() { - evalLPUSH([]string{"EXISTING_KEY", "mock_value"}, store) - }, - input: []string{"ENCODING", "EXISTING_KEY"}, - migratedOutput: EvalResponse{ - Result: "deque", - Error: nil, - }, - }, - } - - runMigratedEvalTests(t, tests, evalOBJECT, store) -} - func testEvalJSONSTRAPPEND(t *testing.T, store *dstore.Store) { tests := map[string]evalTestCase{ "append to single field": { @@ -8440,7 +8390,7 @@ func testEvalJSONSTRAPPEND(t *testing.T, store *dstore.Store) { value := "{\"a\":\"foo\", \"nested1\": {\"a\": \"hello\"}, \"nested2\": {\"a\": 31}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"doc1", "$.nested1.a", "\"baz\""}, @@ -8465,7 +8415,7 @@ func testEvalJSONSTRAPPEND(t *testing.T, store *dstore.Store) { value := "\"abcd\"" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) }, input: []string{"doc1", "$", "\"piu\""}, @@ -8488,7 +8438,7 @@ func BenchmarkEvalJSONSTRAPPEND(b *testing.B) { value := "{\"a\":\"foo\", \"nested1\": {\"a\": \"hello\"}, \"nested2\": {\"a\": 31}}" var rootData interface{} _ = sonic.Unmarshal([]byte(value), &rootData) - obj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + obj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, obj) b.ResetTimer() @@ -8555,7 +8505,7 @@ func testEvalZPOPMAX(t *testing.T, store *dstore.Store) { }, "ZPOPMAX on an empty sorted set": { setup: func() { - store.Put("myzset", store.NewObj(sortedset.New(), -1, object.ObjTypeSortedSet, object.ObjEncodingBTree)) + store.Put("myzset", store.NewObj(sortedset.New(), -1, object.ObjTypeSortedSet)) }, input: []string{"myzset"}, migratedOutput: EvalResponse{ @@ -8685,7 +8635,7 @@ func testEvalINCR(t *testing.T, store *dstore.Store) { name: "INCR key exists", setup: func() { key := "KEY2" - obj := store.NewObj(int64(1), -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(int64(1), -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"KEY2"}, @@ -8695,7 +8645,7 @@ func testEvalINCR(t *testing.T, store *dstore.Store) { name: "INCR key holding string value", setup: func() { key := "KEY3" - obj := store.NewObj("VAL1", -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj("VAL1", -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"KEY3"}, @@ -8726,7 +8676,7 @@ func testEvalINCR(t *testing.T, store *dstore.Store) { name: "INCR Max Overflow", setup: func() { key := "KEY5" - obj := store.NewObj(int64(math.MaxInt64), -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(int64(math.MaxInt64), -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"KEY5"}, @@ -8772,7 +8722,7 @@ func testEvalINCRBY(t *testing.T, store *dstore.Store) { name: "INCRBY key exists", setup: func() { key := "KEY2" - obj := store.NewObj(int64(1), -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(int64(1), -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"KEY2", "3"}, @@ -8782,7 +8732,7 @@ func testEvalINCRBY(t *testing.T, store *dstore.Store) { name: "INCRBY key holding string value", setup: func() { key := "KEY3" - obj := store.NewObj("VAL1", -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj("VAL1", -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"KEY3", "2"}, @@ -8813,7 +8763,7 @@ func testEvalINCRBY(t *testing.T, store *dstore.Store) { name: "INCRBY Max Overflow", setup: func() { key := "KEY5" - obj := store.NewObj(int64(math.MaxInt64-3), -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(int64(math.MaxInt64-3), -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"KEY5", "4"}, @@ -8859,7 +8809,7 @@ func testEvalDECR(t *testing.T, store *dstore.Store) { name: "DECR key exists", setup: func() { key := "KEY2" - obj := store.NewObj(int64(1), -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(int64(1), -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"KEY2"}, @@ -8869,7 +8819,7 @@ func testEvalDECR(t *testing.T, store *dstore.Store) { name: "DECR key holding string value", setup: func() { key := "KEY3" - obj := store.NewObj("VAL1", -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj("VAL1", -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"KEY3"}, @@ -8900,7 +8850,7 @@ func testEvalDECR(t *testing.T, store *dstore.Store) { name: "DECR Min Overflow", setup: func() { key := "KEY5" - obj := store.NewObj(int64(math.MinInt64), -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(int64(math.MinInt64), -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"KEY5"}, @@ -8946,7 +8896,7 @@ func testEvalDECRBY(t *testing.T, store *dstore.Store) { name: "DECRBY key exists", setup: func() { key := "KEY2" - obj := store.NewObj(int64(1), -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(int64(1), -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"KEY2", "3"}, @@ -8956,7 +8906,7 @@ func testEvalDECRBY(t *testing.T, store *dstore.Store) { name: "DECRBY key holding string value", setup: func() { key := "KEY3" - obj := store.NewObj("VAL1", -1, object.ObjTypeString, object.ObjEncodingEmbStr) + obj := store.NewObj("VAL1", -1, object.ObjTypeString) store.Put(key, obj) }, input: []string{"KEY3", "2"}, @@ -8987,7 +8937,7 @@ func testEvalDECRBY(t *testing.T, store *dstore.Store) { name: "DECRBY Min Overflow", setup: func() { key := "KEY5" - obj := store.NewObj(int64(math.MinInt64+3), -1, object.ObjTypeInt, object.ObjEncodingInt) + obj := store.NewObj(int64(math.MinInt64+3), -1, object.ObjTypeInt) store.Put(key, obj) }, input: []string{"KEY5", "4"}, @@ -9227,7 +9177,7 @@ func testEvalLINSERT(t *testing.T, store *dstore.Store) { evalSET([]string{"EXISTING_KEY", "mock_value"}, store) }, input: []string{"EXISTING_KEY", "before", "mock_value", "element"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: errors.New("-WRONGTYPE Operation against a key holding the wrong kind of value")}, }, } runMigratedEvalTests(t, tests, evalLINSERT, store) @@ -9273,7 +9223,7 @@ func testEvalLRANGE(t *testing.T, store *dstore.Store) { evalSET([]string{"EXISTING_KEY", "mock_value"}, store) }, input: []string{"EXISTING_KEY", "0", "4"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: errors.New("-WRONGTYPE Operation against a key holding the wrong kind of value")}, }, } runMigratedEvalTests(t, tests, evalLRANGE, store) diff --git a/internal/eval/hmap_test.go b/internal/eval/hmap_test.go index 40fcc8005..1e30be0a0 100644 --- a/internal/eval/hmap_test.go +++ b/internal/eval/hmap_test.go @@ -79,7 +79,7 @@ func TestGetValueFromHashMap(t *testing.T) { hmap.Set(field, value) obj := &object.Obj{ - TypeEncoding: object.ObjTypeHashMap | object.ObjEncodingHashMap, + Type: object.ObjTypeHashMap, Value: hmap, LastAccessedAt: uint32(time.Now().Unix()), } diff --git a/internal/eval/sortedset/sorted_set.go b/internal/eval/sortedset/sorted_set.go index f24a62a93..51d64efd5 100644 --- a/internal/eval/sortedset/sorted_set.go +++ b/internal/eval/sortedset/sorted_set.go @@ -42,7 +42,7 @@ func New() *Set { } func FromObject(obj *object.Obj) (value *Set, err []byte) { - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeSortedSet, object.ObjEncodingBTree); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeSortedSet); err != nil { return nil, err } value, ok := obj.Value.(*Set) diff --git a/internal/eval/store_eval.go b/internal/eval/store_eval.go index d627c8b6f..37b694f5e 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, oEnc := deduceTypeEncoding(value) + oType := deduceType(value) for i := 2; i < len(args); i++ { arg := strings.ToUpper(args[i]) @@ -296,17 +296,17 @@ func evalSET(args []string, store *dstore.Store) *EvalResponse { // Cast the value properly based on the encoding type var storedValue interface{} - switch oEnc { - case object.ObjEncodingInt: + switch oType { + case object.ObjTypeInt: storedValue, _ = strconv.ParseInt(value, 10, 64) - case object.ObjEncodingEmbStr, object.ObjEncodingRaw: + case object.ObjTypeString: storedValue = value default: - return makeEvalError(diceerrors.ErrUnsupportedEncoding(int(oEnc))) + return makeEvalError(diceerrors.ErrUnsupportedEncoding(int(oType))) } // putting the k and value in a Hash Table - store.Put(key, store.NewObj(storedValue, exDurationMs, oType, oEnc), dstore.WithKeepTTL(keepttl)) + store.Put(key, store.NewObj(storedValue, exDurationMs, oType), dstore.WithKeepTTL(keepttl)) if oldVal != nil { return makeEvalResult(*oldVal) } @@ -338,8 +338,8 @@ func evalGET(args []string, store *dstore.Store) *EvalResponse { } // Decode and return the value based on its encoding - switch _, oEnc := object.ExtractTypeEncoding(obj); oEnc { - case object.ObjEncodingInt: + switch oType := object.ExtractType(obj); oType { + case object.ObjTypeInt: // Value is stored as an int64, so use type assertion if IsInt64(obj.Value) { return &EvalResponse{ @@ -358,7 +358,7 @@ func evalGET(args []string, store *dstore.Store) *EvalResponse { } } - case object.ObjEncodingEmbStr, object.ObjEncodingRaw: + case object.ObjTypeString: // Value is stored as a string, use type assertion if IsString(obj.Value) { return &EvalResponse{ @@ -377,7 +377,7 @@ func evalGET(args []string, store *dstore.Store) *EvalResponse { } } - case object.ObjEncodingByteArray: + case object.ObjTypeByteArray: // Value is stored as a bytearray, use type assertion if val, ok := obj.Value.(*ByteArray); ok { return &EvalResponse{ @@ -494,7 +494,7 @@ func evalHEXISTS(args []string, store *dstore.Store) *EvalResponse { Error: nil, } } - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Error: diceerrors.ErrGeneral(diceerrors.WrongTypeErr), Result: nil, @@ -539,7 +539,7 @@ func evalHKEYS(args []string, store *dstore.Store) *EvalResponse { var result []string if obj != nil { - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Error: diceerrors.ErrGeneral(diceerrors.WrongTypeErr), Result: nil, @@ -586,7 +586,7 @@ func evalHVALS(args []string, store *dstore.Store) *EvalResponse { } } - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Error: diceerrors.ErrGeneral(diceerrors.WrongTypeErr), Result: nil, @@ -642,8 +642,8 @@ func evalGETRANGE(args []string, store *dstore.Store) *EvalResponse { } var str string - switch _, oEnc := object.ExtractTypeEncoding(obj); oEnc { - case object.ObjEncodingEmbStr, object.ObjEncodingRaw: + switch oType := object.ExtractType(obj); oType { + case object.ObjTypeString: if val, ok := obj.Value.(string); ok { str = val } else { @@ -652,9 +652,9 @@ func evalGETRANGE(args []string, store *dstore.Store) *EvalResponse { Error: diceerrors.ErrGeneral("expected string but got another type"), } } - case object.ObjEncodingInt: + case object.ObjTypeInt: str = strconv.FormatInt(obj.Value.(int64), 10) - case object.ObjEncodingByteArray: + case object.ObjTypeByteArray: if val, ok := obj.Value.(*ByteArray); ok { str = string(val.data) } else { @@ -881,7 +881,7 @@ func shouldSkipMember(score, currentScore float64, exists bool, flags map[string // storeUpdatedSet stores the updated sorted set in the store. func storeUpdatedSet(store *dstore.Store, key string, sortedSet *sortedset.Set) { - store.Put(key, store.NewObj(sortedSet, -1, object.ObjTypeSortedSet, object.ObjEncodingBTree), dstore.WithPutCmd(dstore.ZAdd)) + store.Put(key, store.NewObj(sortedSet, -1, object.ObjTypeSortedSet), dstore.WithPutCmd(dstore.ZAdd)) } // getOrCreateSortedSet fetches the sorted set if it exists, otherwise creates a new one. @@ -1096,10 +1096,10 @@ func evalAPPEND(args []string, store *dstore.Store) *EvalResponse { // Key does not exist, create a new key if obj == nil { // Deduce type and encoding based on the value if no leading zeros - oType, oEnc := deduceTypeEncoding(value) + oType := deduceType(value) // Transform the value based on the type and encoding - storedValue, err := storeValueWithEncoding(value, oEnc) + storedValue, err := storeValueWithType(value, oType) if err != nil { return &EvalResponse{ Result: nil, @@ -1107,7 +1107,7 @@ func evalAPPEND(args []string, store *dstore.Store) *EvalResponse { } } - store.Put(key, store.NewObj(storedValue, exDurationMs, oType, oEnc)) + store.Put(key, store.NewObj(storedValue, exDurationMs, oType)) return &EvalResponse{ Result: len(value), Error: nil, @@ -1121,10 +1121,10 @@ func evalAPPEND(args []string, store *dstore.Store) *EvalResponse { Error: diceerrors.ErrWrongTypeOperation, } } - _, currentEnc := object.ExtractTypeEncoding(obj) + oType := object.ExtractType(obj) // Transform the value based on the current encoding - currentValue, err := convertValueToString(obj, currentEnc) + currentValue, err := convertValueToString(obj, oType) if err != nil { // If the encoding is neither integer nor string, return a "wrong type" error return &EvalResponse{ @@ -1139,7 +1139,7 @@ func evalAPPEND(args []string, store *dstore.Store) *EvalResponse { // We need to store the new appended value as a string // Even if append is performed on integers, the result will be stored as a string // This is consistent with the redis implementation as append is considered a string operation - store.Put(key, store.NewObj(newValue, exDurationMs, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put(key, store.NewObj(newValue, exDurationMs, object.ObjTypeString)) return &EvalResponse{ Result: len(newValue), Error: nil, @@ -1273,8 +1273,7 @@ func evalJSONCLEAR(args []string, store *dstore.Store) *EvalResponse { } } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -1295,7 +1294,7 @@ func evalJSONCLEAR(args []string, store *dstore.Store) *EvalResponse { if len(args) == 1 || path == defaultRootPath { if jsonData != struct{}{} { // If path is root and len(args) == 1, return it instantly - newObj := store.NewObj(struct{}{}, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + newObj := store.NewObj(struct{}{}, -1, object.ObjTypeJSON) store.Put(key, newObj) countClear++ return &EvalResponse{ @@ -1384,8 +1383,7 @@ func jsonGETHelper(store *dstore.Store, path, key string) *EvalResponse { } // Check if the object is of JSON type - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -1525,15 +1523,7 @@ func evalJSONSET(args []string, store *dstore.Store) *EvalResponse { } } else { // If the key exists, check if it's a JSON object - err := object.AssertType(obj.TypeEncoding, object.ObjTypeJSON) - if err != nil { - return &EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongTypeOperation, - } - } - err = object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingJSON) - if err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeJSON); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -1565,7 +1555,7 @@ func evalJSONSET(args []string, store *dstore.Store) *EvalResponse { } // Create a new object with the updated JSON data - newObj := store.NewObj(rootData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + newObj := store.NewObj(rootData, -1, object.ObjTypeJSON) store.Put(key, newObj) return &EvalResponse{ Result: clientio.OK, @@ -1638,8 +1628,7 @@ func evalJSONTYPE(args []string, store *dstore.Store) *EvalResponse { } } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -1717,7 +1706,7 @@ func evalPFADD(args []string, store *dstore.Store) *EvalResponse { hll.Insert([]byte(arg)) } - obj = store.NewObj(hll, -1, object.ObjTypeString, object.ObjEncodingRaw) + obj = store.NewObj(hll, -1, object.ObjTypeString) store.Put(key, obj, dstore.WithPutCmd(dstore.PFADD)) return &EvalResponse{ @@ -1738,7 +1727,7 @@ func evalPFADD(args []string, store *dstore.Store) *EvalResponse { existingHll.Insert([]byte(arg)) } - obj = store.NewObj(existingHll, -1, object.ObjTypeString, object.ObjEncodingRaw) + obj = store.NewObj(existingHll, -1, object.ObjTypeString) store.Put(key, obj, dstore.WithPutCmd(dstore.PFADD)) if newCardinality := existingHll.Estimate(); initialCardinality != newCardinality { @@ -1804,8 +1793,7 @@ func evalJSONSTRLEN(args []string, store *dstore.Store) *EvalResponse { path := args[1] // Check if the object is of JSON type - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -1919,8 +1907,7 @@ func evalJSONOBJLEN(args []string, store *dstore.Store) *EvalResponse { } // check if the object is json - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -2059,7 +2046,7 @@ func evalPFMERGE(args []string, store *dstore.Store) *EvalResponse { } // Save the mergedHll - obj = store.NewObj(mergedHll, -1, object.ObjTypeString, object.ObjEncodingRaw) + obj = store.NewObj(mergedHll, -1, object.ObjTypeString) store.Put(destKey, obj, dstore.WithPutCmd(dstore.PFMERGE)) return &EvalResponse{ @@ -2183,7 +2170,7 @@ func evalHINCRBY(args []string, store *dstore.Store) *EvalResponse { key := args[0] obj := store.Get(key) if obj != nil { - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -2205,7 +2192,7 @@ func evalHINCRBY(args []string, store *dstore.Store) *EvalResponse { } } - obj = store.NewObj(hashmap, -1, object.ObjTypeHashMap, object.ObjEncodingHashMap) + obj = store.NewObj(hashmap, -1, object.ObjTypeHashMap) store.Put(key, obj) return &EvalResponse{ @@ -2242,7 +2229,7 @@ func evalHINCRBYFLOAT(args []string, store *dstore.Store) *EvalResponse { obj := store.Get(key) var hashmap HashMap if obj != nil { - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -2264,7 +2251,7 @@ func evalHINCRBYFLOAT(args []string, store *dstore.Store) *EvalResponse { } } - obj = store.NewObj(hashmap, -1, object.ObjTypeHashMap, object.ObjEncodingHashMap) + obj = store.NewObj(hashmap, -1, object.ObjTypeHashMap) store.Put(key, obj) return &EvalResponse{ @@ -2296,7 +2283,7 @@ func evalHRANDFIELD(args []string, store *dstore.Store) *EvalResponse { } } - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -2432,7 +2419,7 @@ func incrDecrCmd(args []string, incr int64, store *dstore.Store) *EvalResponse { key := args[0] obj := store.Get(key) if obj == nil { - obj = store.NewObj(incr, -1, object.ObjTypeInt, object.ObjEncodingInt) + obj = store.NewObj(incr, -1, object.ObjTypeInt) store.Put(key, obj) return &EvalResponse{ Result: incr, @@ -2441,17 +2428,14 @@ func incrDecrCmd(args []string, incr int64, store *dstore.Store) *EvalResponse { } // if the type is not KV : return wrong type error // if the encoding or type is not int : return value is not an int error - errStr := object.AssertType(obj.TypeEncoding, object.ObjTypeString) - if errStr == nil { + if err := object.AssertTypeWithError(obj.Type, object.ObjTypeString); err == nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrIntegerOutOfRange, } } - errTypeInt := object.AssertType(obj.TypeEncoding, object.ObjTypeInt) - errEncInt := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingInt) - if errEncInt != nil || errTypeInt != nil { + if errTypeInt := object.AssertType(obj.Type, object.ObjTypeInt); errTypeInt != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -2504,8 +2488,8 @@ func incrByFloatCmd(args []string, incr float64, store *dstore.Store) *EvalRespo if obj == nil { strValue := formatFloat(incr, false) - oType, oEnc := deduceTypeEncoding(strValue) - obj = store.NewObj(strValue, -1, oType, oEnc) + oType := deduceType(strValue) + obj = store.NewObj(strValue, -1, oType) store.Put(key, obj) return &EvalResponse{ Result: strValue, @@ -2513,8 +2497,8 @@ func incrByFloatCmd(args []string, incr float64, store *dstore.Store) *EvalRespo } } - errString := object.AssertType(obj.TypeEncoding, object.ObjTypeString) - errInt := object.AssertType(obj.TypeEncoding, object.ObjTypeInt) + errString := object.AssertType(obj.Type, object.ObjTypeString) + errInt := object.AssertType(obj.Type, object.ObjTypeInt) if errString != nil && errInt != nil { return &EvalResponse{ Result: nil, @@ -2538,14 +2522,14 @@ func incrByFloatCmd(args []string, incr float64, store *dstore.Store) *EvalRespo } strValue := formatFloat(value, true) - oType, oEnc := deduceTypeEncoding(strValue) + oType := deduceType(strValue) // Remove the trailing decimal for integer values // to maintain consistency with redis strValue = strings.TrimSuffix(strValue, ".0") obj.Value = strValue - obj.TypeEncoding = oType | oEnc + obj.Type = oType return &EvalResponse{ Result: strValue, @@ -2673,7 +2657,7 @@ func evalRestore(args []string, store *dstore.Store) *EvalResponse { return makeEvalError(diceerrors.ErrGeneral("deserialization failed")) } - newobj := store.NewObj(obj.Value, ttl, obj.TypeEncoding, obj.TypeEncoding) + newobj := store.NewObj(obj.Value, ttl, obj.Type) var keepttl = true if ttl > 0 { @@ -2709,7 +2693,7 @@ func evalHLEN(args []string, store *dstore.Store) *EvalResponse { } } - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -2745,7 +2729,7 @@ func evalHSTRLEN(args []string, store *dstore.Store) *EvalResponse { var hashMap HashMap if obj != nil { - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -2806,7 +2790,7 @@ func evalHSCAN(args []string, store *dstore.Store) *EvalResponse { } } - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -3066,8 +3050,7 @@ func evalJSONARRTRIM(args []string, store *dstore.Store) *EvalResponse { } } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrGeneral(string(errWithMessage)), @@ -3147,17 +3130,10 @@ func evalLPUSH(args []string, store *dstore.Store) *EvalResponse { obj := store.Get(args[0]) if obj == nil { - obj = store.NewObj(NewDeque(), -1, object.ObjTypeByteList, object.ObjEncodingDeque) - } - - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeByteList); err != nil { - return &EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongTypeOperation, - } + obj = store.NewObj(NewDeque(), -1, object.ObjTypeDequeue) } - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingDeque); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeDequeue); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -3192,17 +3168,10 @@ func evalRPUSH(args []string, store *dstore.Store) *EvalResponse { obj := store.Get(args[0]) if obj == nil { - obj = store.NewObj(NewDeque(), -1, object.ObjTypeByteList, object.ObjEncodingDeque) - } - - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeByteList); err != nil { - return &EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongTypeOperation, - } + obj = store.NewObj(NewDeque(), -1, object.ObjTypeDequeue) } - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingDeque); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeDequeue); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -3273,14 +3242,7 @@ func evalLPOP(args []string, store *dstore.Store) *EvalResponse { } } - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeByteList); err != nil { - return &EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongTypeOperation, - } - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingDeque); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeDequeue); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -3342,14 +3304,7 @@ func evalRPOP(args []string, store *dstore.Store) *EvalResponse { } } - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeByteList); err != nil { - return &EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongTypeOperation, - } - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingDeque); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeDequeue); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -3392,7 +3347,7 @@ func evalLLEN(args []string, store *dstore.Store) *EvalResponse { } } - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeByteList, object.ObjEncodingDeque); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeDequeue); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -3431,8 +3386,7 @@ func evalJSONARRAPPEND(args []string, store *dstore.Store) *EvalResponse { Error: nil, } } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -3534,8 +3488,7 @@ func evalJSONARRLEN(args []string, store *dstore.Store) *EvalResponse { } } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -3677,8 +3630,7 @@ func evalJSONARRPOP(args []string, store *dstore.Store) *EvalResponse { } } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -3714,7 +3666,7 @@ func evalJSONARRPOP(args []string, store *dstore.Store) *EvalResponse { } // save the remaining array - newObj := store.NewObj(arr, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + newObj := store.NewObj(arr, -1, object.ObjTypeJSON) store.Put(key, newObj) return &EvalResponse{ @@ -3788,8 +3740,7 @@ func evalJSONARRINSERT(args []string, store *dstore.Store) *EvalResponse { } } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrGeneral(string(errWithMessage)), @@ -3925,8 +3876,7 @@ func evalJSONOBJKEYS(args []string, store *dstore.Store) *EvalResponse { } // Check if the object is of JSON type - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrGeneral(string(errWithMessage)), @@ -4022,8 +3972,7 @@ func evalJSONRESP(args []string, store *dstore.Store) *EvalResponse { } // Check if the object is of JSON type - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -4158,8 +4107,7 @@ func evalJSONDebugMemory(args []string, store *dstore.Store) *EvalResponse { } // check if the object is a valid JSON - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrInvalidJSONPathType, @@ -4179,7 +4127,7 @@ func evalJSONDebugMemory(args []string, store *dstore.Store) *EvalResponse { } } // add memory used by storage object - size += int(unsafe.Sizeof(obj)) + calculateSizeInBytes(obj.LastAccessedAt) + calculateSizeInBytes(obj.TypeEncoding) + size += int(unsafe.Sizeof(obj)) + calculateSizeInBytes(obj.LastAccessedAt) + calculateSizeInBytes(obj.Type) return &EvalResponse{ Result: size, @@ -4419,8 +4367,8 @@ func evalGETEX(args []string, store *dstore.Store) *EvalResponse { } } - if object.AssertType(obj.TypeEncoding, object.ObjTypeSet) == nil || - object.AssertType(obj.TypeEncoding, object.ObjTypeJSON) == nil { + if object.AssertType(obj.Type, object.ObjTypeSet) == nil || + object.AssertType(obj.Type, object.ObjTypeJSON) == nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -4474,7 +4422,7 @@ func evalGETDEL(args []string, store *dstore.Store) *EvalResponse { } // If the object exists, check if it is a Set object. - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeSet); err == nil { + if err := object.AssertType(obj.Type, object.ObjTypeSet); err == nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -4482,7 +4430,7 @@ func evalGETDEL(args []string, store *dstore.Store) *EvalResponse { } // If the object exists, check if it is a JSON object. - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeJSON); err == nil { + if err := object.AssertType(obj.Type, object.ObjTypeJSON); err == nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -4493,8 +4441,8 @@ func evalGETDEL(args []string, store *dstore.Store) *EvalResponse { objVal := store.GetDel(key) // Decode and return the value based on its encoding - switch _, oEnc := object.ExtractTypeEncoding(objVal); oEnc { - case object.ObjEncodingInt: + switch oType := object.ExtractType(objVal); oType { + case object.ObjTypeInt: // Value is stored as an int64, so use type assertion if IsInt64(objVal.Value) { return &EvalResponse{ @@ -4513,7 +4461,7 @@ func evalGETDEL(args []string, store *dstore.Store) *EvalResponse { } } - case object.ObjEncodingEmbStr, object.ObjEncodingRaw: + case object.ObjTypeString: // Value is stored as a string, use type assertion if IsString(objVal.Value) { return &EvalResponse{ @@ -4532,7 +4480,7 @@ func evalGETDEL(args []string, store *dstore.Store) *EvalResponse { } } - case object.ObjEncodingByteArray: + case object.ObjTypeByteArray: // Value is stored as a bytearray, use type assertion if val, ok := objVal.Value.(*ByteArray); ok { return &EvalResponse{ @@ -4562,7 +4510,7 @@ func insertInHashMap(args []string, store *dstore.Store) (int64, error) { var hashMap HashMap if obj != nil { - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return 0, diceerrors.ErrWrongTypeOperation } hashMap = obj.Value.(HashMap) @@ -4575,7 +4523,7 @@ func insertInHashMap(args []string, store *dstore.Store) (int64, error) { return 0, err } - obj = store.NewObj(hashMap, -1, object.ObjTypeHashMap, object.ObjEncodingHashMap) + obj = store.NewObj(hashMap, -1, object.ObjTypeHashMap) store.Put(key, obj) return numKeys, nil @@ -4674,7 +4622,7 @@ func evalHMGET(args []string, store *dstore.Store) *EvalResponse { } // Assert that the object is of type HashMap - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -4741,7 +4689,7 @@ func evalHGETALL(args []string, store *dstore.Store) *EvalResponse { var results []string if obj != nil { - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -4814,7 +4762,7 @@ func evalHDEL(args []string, store *dstore.Store) *EvalResponse { } } - if err := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeHashMap, object.ObjEncodingHashMap); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -4866,18 +4814,11 @@ func evalSADD(args []string, store *dstore.Store) *EvalResponse { // If the object does not exist, create a new set object. value := make(map[string]struct{}, lengthOfItems) // Create a new object. - obj = store.NewObj(value, exDurationMs, object.ObjTypeSet, object.ObjEncodingSetStr) + obj = store.NewObj(value, exDurationMs, object.ObjTypeSet) store.Put(key, obj, dstore.WithKeepTTL(keepttl)) } - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeSet); err != nil { - return &EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongTypeOperation, - } - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingSetStr); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeSet); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -4926,14 +4867,7 @@ func evalSREM(args []string, store *dstore.Store) *EvalResponse { } // If the object exists, check if it is a set object. - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeSet); err != nil { - return &EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongTypeOperation, - } - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingSetStr); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeSet); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -4980,14 +4914,7 @@ func evalSCARD(args []string, store *dstore.Store) *EvalResponse { } // If the object exists, check if it is a set object. - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeSet); err != nil { - return &EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongTypeOperation, - } - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingSetStr); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeSet); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -5025,14 +4952,7 @@ func evalSMEMBERS(args []string, store *dstore.Store) *EvalResponse { } // If the object exists, check if it is a set object. - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeSet); err != nil { - return &EvalResponse{ - Result: nil, - Error: diceerrors.ErrWrongTypeOperation, - } - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingSetStr); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeSet); err != nil { return &EvalResponse{ Result: nil, Error: diceerrors.ErrWrongTypeOperation, @@ -5077,19 +4997,10 @@ func evalLRANGE(args []string, store *dstore.Store) *EvalResponse { return makeEvalResult([]string{}) } - // if object is a set type, return error - if object.AssertType(obj.TypeEncoding, object.ObjTypeSet) == nil { + if object.AssertType(obj.Type, object.ObjTypeDequeue) != nil { return makeEvalError(errors.New(diceerrors.WrongTypeErr)) } - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeByteList); err != nil { - return makeEvalError(err) - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingDeque); err != nil { - return makeEvalError(err) - } - q := obj.Value.(*Deque) res, err := q.LRange(start, stop) if err != nil { @@ -5119,18 +5030,10 @@ func evalLINSERT(args []string, store *dstore.Store) *EvalResponse { } // if object is a set type, return error - if object.AssertType(obj.TypeEncoding, object.ObjTypeSet) == nil { + if object.AssertType(obj.Type, object.ObjTypeDequeue) != nil { return makeEvalError(errors.New(diceerrors.WrongTypeErr)) } - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeByteList); err != nil { - return makeEvalError(err) - } - - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingDeque); err != nil { - return makeEvalError(err) - } - q := obj.Value.(*Deque) res, err := q.LInsert(pivot, element, beforeAfter) if err != nil { @@ -5171,15 +5074,15 @@ func evalSETBIT(args []string, store *dstore.Store) *EvalResponse { requiredByteArraySize := offset>>3 + 1 if obj == nil { - obj = store.NewObj(NewByteArray(int(requiredByteArraySize)), -1, object.ObjTypeByteArray, object.ObjEncodingByteArray) + obj = store.NewObj(NewByteArray(int(requiredByteArraySize)), -1, object.ObjTypeByteArray) store.Put(args[0], obj) } - if object.AssertType(obj.TypeEncoding, object.ObjTypeByteArray) == nil || - object.AssertType(obj.TypeEncoding, object.ObjTypeString) == nil || - object.AssertType(obj.TypeEncoding, object.ObjTypeInt) == nil { + if object.AssertType(obj.Type, object.ObjTypeByteArray) == nil || + object.AssertType(obj.Type, object.ObjTypeString) == nil || + object.AssertType(obj.Type, object.ObjTypeInt) == nil { var byteArray *ByteArray - oType, oEnc := object.ExtractTypeEncoding(obj) + oType := object.ExtractType(obj) switch oType { case object.ObjTypeByteArray: @@ -5212,7 +5115,7 @@ func evalSETBIT(args []string, store *dstore.Store) *EvalResponse { // We are returning newObject here so it is thread-safe // Old will be removed by GC - newObj, err := ByteSliceToObj(store, obj, byteArray.data, oType, oEnc) + newObj, err := ByteSliceToObj(store, obj, byteArray.data, oType) if err != nil { return &EvalResponse{ Result: nil, @@ -5277,7 +5180,7 @@ func evalGETBIT(args []string, store *dstore.Store) *EvalResponse { } requiredByteArraySize := offset>>3 + 1 - switch oType, _ := object.ExtractTypeEncoding(obj); oType { + switch oType := object.ExtractType(obj); oType { case object.ObjTypeSet: return &EvalResponse{ Result: nil, @@ -5373,14 +5276,14 @@ func evalBITCOUNT(args []string, store *dstore.Store) *EvalResponse { var valueLength int64 switch { - case object.AssertType(obj.TypeEncoding, object.ObjTypeByteArray) == nil: + case object.AssertType(obj.Type, object.ObjTypeByteArray) == nil: byteArray := obj.Value.(*ByteArray) value = byteArray.data valueLength = byteArray.Length - case object.AssertType(obj.TypeEncoding, object.ObjTypeString) == nil: + case object.AssertType(obj.Type, object.ObjTypeString) == nil: value = []byte(obj.Value.(string)) valueLength = int64(len(value)) - case object.AssertType(obj.TypeEncoding, object.ObjTypeInt) == nil: + case object.AssertType(obj.Type, object.ObjTypeInt) == nil: value = []byte(strconv.FormatInt(obj.Value.(int64), 10)) valueLength = int64(len(value)) default: @@ -5520,13 +5423,13 @@ func bitfieldEvalGeneric(args []string, store *dstore.Store, isReadOnly bool) *E key := args[0] obj := store.Get(key) if obj == nil { - obj = store.NewObj(NewByteArray(1), -1, object.ObjTypeByteArray, object.ObjEncodingByteArray) + obj = store.NewObj(NewByteArray(1), -1, object.ObjTypeByteArray) store.Put(args[0], obj) } var value *ByteArray var err error - switch oType, _ := object.ExtractTypeEncoding(obj); oType { + switch oType := object.ExtractType(obj); oType { case object.ObjTypeByteArray: value = obj.Value.(*ByteArray) case object.ObjTypeString, object.ObjTypeInt: @@ -5644,8 +5547,7 @@ func evalJSONSTRAPPEND(args []string, store *dstore.Store) *EvalResponse { return makeEvalError(diceerrors.ErrKeyDoesNotExist) } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return makeEvalError(diceerrors.ErrWrongTypeOperation) } @@ -5713,8 +5615,7 @@ func evalJSONTOGGLE(args []string, store *dstore.Store) *EvalResponse { return makeEvalError(diceerrors.ErrKeyDoesNotExist) } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return makeEvalError(diceerrors.ErrWrongTypeOperation) } @@ -5802,8 +5703,7 @@ func evalJSONDEL(args []string, store *dstore.Store) *EvalResponse { return makeEvalResult(clientio.IntegerZero) } - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return makeEvalError(diceerrors.ErrWrongTypeOperation) } @@ -5838,7 +5738,7 @@ func evalJSONDEL(args []string, store *dstore.Store) *EvalResponse { return makeEvalError(diceerrors.ErrInternalServer) // no need to send actual internal error } // Create a new object with the updated JSON data - newObj := store.NewObj(jsonData, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + newObj := store.NewObj(jsonData, -1, object.ObjTypeJSON) store.Put(key, newObj) return makeEvalResult(len(results)) @@ -5917,8 +5817,7 @@ func evalJSONNUMMULTBY(args []string, store *dstore.Store) *EvalResponse { } // Check if the object is of JSON type - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return makeEvalError(diceerrors.ErrWrongTypeOperation) } path := args[1] @@ -5975,8 +5874,8 @@ func evalJSONNUMMULTBY(args []string, store *dstore.Store) *EvalResponse { resultString := `[` + strings.Join(resultArray, ",") + `]` newObj := &object.Obj{ - Value: jsonData, - TypeEncoding: object.ObjTypeJSON, + Value: jsonData, + Type: object.ObjTypeJSON, } exp, ok := dstore.GetExpiry(obj, store) @@ -6084,8 +5983,7 @@ func evalJSONNUMINCRBY(args []string, store *dstore.Store) *EvalResponse { } // Check if the object is of JSON type - errWithMessage := object.AssertTypeAndEncoding(obj.TypeEncoding, object.ObjTypeJSON, object.ObjEncodingJSON) - if errWithMessage != nil { + if errWithMessage := object.AssertType(obj.Type, object.ObjTypeJSON); errWithMessage != nil { return makeEvalError(diceerrors.ErrWrongTypeOperation) } @@ -6256,7 +6154,7 @@ func evalGEOADD(args []string, store *dstore.Store) *EvalResponse { } } - obj = store.NewObj(ss, -1, object.ObjTypeSortedSet, object.ObjEncodingBTree) + obj = store.NewObj(ss, -1, object.ObjTypeSortedSet) store.Put(key, obj) return &EvalResponse{ @@ -6485,10 +6383,10 @@ func evalTYPE(args []string, store *dstore.Store) *EvalResponse { } var typeStr string - switch oType, _ := object.ExtractTypeEncoding(obj); oType { + switch oType := object.ExtractType(obj); oType { case object.ObjTypeString, object.ObjTypeInt, object.ObjTypeByteArray: typeStr = "string" - case object.ObjTypeByteList: + case object.ObjTypeDequeue: typeStr = "list" case object.ObjTypeSet: typeStr = "set" @@ -6532,7 +6430,7 @@ func evalTYPE(args []string, store *dstore.Store) *EvalResponse { // var value []byte -// switch oType, _ := object.ExtractTypeEncoding(obj); oType { +// switch oType, _ := object.ExtractType(obj); oType { // case object.ObjTypeByteArray: // byteArray := obj.Value.(*ByteArray) // byteArrayObject := *byteArray @@ -6552,7 +6450,7 @@ func evalTYPE(args []string, store *dstore.Store) *EvalResponse { // operationResult.ResizeIfNecessary() // // create object related to result -// obj = store.NewObj(operationResult, -1, object.ObjTypeByteArray, object.ObjEncodingByteArray) +// obj = store.NewObj(operationResult, -1, object.ObjTypeByteArray) // // store the result in destKey // store.Put(destKey, obj) @@ -6569,7 +6467,7 @@ func evalTYPE(args []string, store *dstore.Store) *EvalResponse { // for i := 0; i < len(value); i++ { // result[i] = ^value[i] // } -// resOType, resOEnc := deduceTypeEncoding(string(result)) +// resOType, resOEnc := deduceType(string(result)) // var storedValue interface{} // if resOType == object.ObjTypeInt { // storedValue, _ = strconv.ParseInt(string(result), 10, 64) @@ -6593,7 +6491,7 @@ func evalTYPE(args []string, store *dstore.Store) *EvalResponse { // values[i] = make([]byte, 0) // } else { // // handle the case when it is byte array -// switch oType, _ := object.ExtractTypeEncoding(obj); oType { +// switch oType, _ := object.ExtractType(obj); oType { // case object.ObjTypeByteArray: // byteArray := obj.Value.(*ByteArray) // byteArrayObject := *byteArray @@ -6654,7 +6552,7 @@ func evalTYPE(args []string, store *dstore.Store) *EvalResponse { // operationResult.Length = int64(len(result)) // // create object related to result -// operationResultObject := store.NewObj(operationResult, -1, object.ObjTypeByteArray, object.ObjEncodingByteArray) +// operationResultObject := store.NewObj(operationResult, -1, object.ObjTypeByteArray) // // store the result in destKey // store.Put(destKey, operationResultObject) @@ -6691,65 +6589,6 @@ func evalObjectIdleTime(key string, store *dstore.Store) *EvalResponse { return makeEvalResult(int64(dstore.GetIdleTime(obj.LastAccessedAt))) } -func evalObjectEncoding(key string, store *dstore.Store) *EvalResponse { - var encodingTypeStr string - - obj := store.GetNoTouch(key) - if obj == nil { - return makeEvalResult(clientio.NIL) - } - - oType, oEnc := object.ExtractTypeEncoding(obj) - switch { - case oType == object.ObjTypeString && oEnc == object.ObjEncodingRaw: - encodingTypeStr = "raw" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeString && oEnc == object.ObjEncodingEmbStr: - encodingTypeStr = "embstr" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeInt && oEnc == object.ObjEncodingInt: - encodingTypeStr = "int" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeByteList && oEnc == object.ObjEncodingDeque: - encodingTypeStr = "deque" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeBitSet && oEnc == object.ObjEncodingBF: - encodingTypeStr = "bf" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeJSON && oEnc == object.ObjEncodingJSON: - encodingTypeStr = "json" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeByteArray && oEnc == object.ObjEncodingByteArray: - encodingTypeStr = "bytearray" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeSet && oEnc == object.ObjEncodingSetStr: - encodingTypeStr = "setstr" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeSet && oEnc == object.ObjEncodingSetInt: - encodingTypeStr = "setint" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeHashMap && oEnc == object.ObjEncodingHashMap: - encodingTypeStr = "hashmap" - return makeEvalResult(encodingTypeStr) - - case oType == object.ObjTypeSortedSet && oEnc == object.ObjEncodingBTree: - encodingTypeStr = "btree" - return makeEvalResult(encodingTypeStr) - - default: - return makeEvalError(diceerrors.ErrWrongTypeOperation) - } -} - func evalOBJECT(args []string, store *dstore.Store) *EvalResponse { if len(args) < 2 { return makeEvalError(diceerrors.ErrWrongArgumentCount("OBJECT")) @@ -6761,8 +6600,6 @@ func evalOBJECT(args []string, store *dstore.Store) *EvalResponse { switch subcommand { case "IDLETIME": return evalObjectIdleTime(key, store) - case "ENCODING": - return evalObjectEncoding(key, store) default: return makeEvalError(diceerrors.ErrSyntax) } diff --git a/internal/eval/type_string.go b/internal/eval/type_string.go index a031509a6..dc4c716be 100644 --- a/internal/eval/type_string.go +++ b/internal/eval/type_string.go @@ -9,23 +9,20 @@ import ( // Similar to // tryObjectEncoding function in Redis -func deduceTypeEncoding(v string) (o, e uint8) { +func deduceType(v string) (o uint8) { // Check if the value has leading zero if len(v) > 1 && v[0] == '0' { // If so, treat as string - return object.ObjTypeString, object.ObjEncodingRaw + return object.ObjTypeString } if _, err := strconv.ParseInt(v, 10, 64); err == nil { - return object.ObjTypeInt, object.ObjEncodingInt + return object.ObjTypeInt } - if len(v) <= 44 { - return object.ObjTypeString, object.ObjEncodingEmbStr - } - return object.ObjTypeString, object.ObjEncodingRaw + return object.ObjTypeString } // Function to handle converting the value based on the encoding type -func storeValueWithEncoding(value string, oEnc uint8) (interface{}, error) { +func storeValueWithType(value string, oType uint8) (interface{}, error) { var returnValue interface{} // treat as string if value has leading zero @@ -34,14 +31,14 @@ func storeValueWithEncoding(value string, oEnc uint8) (interface{}, error) { return value, nil } - switch oEnc { - case object.ObjEncodingInt: + switch oType { + case object.ObjTypeInt: intValue, err := strconv.ParseInt(value, 10, 64) if err != nil { return nil, diceerrors.ErrWrongTypeOperation } returnValue = intValue - case object.ObjEncodingEmbStr, object.ObjEncodingRaw: + case object.ObjTypeString: returnValue = value default: return nil, diceerrors.ErrWrongTypeOperation @@ -51,17 +48,17 @@ func storeValueWithEncoding(value string, oEnc uint8) (interface{}, error) { } // Function to convert the value to a string for concatenation or manipulation -func convertValueToString(obj *object.Obj, oEnc uint8) (string, error) { +func convertValueToString(obj *object.Obj, oType uint8) (string, error) { var currentValueStr string - switch oEnc { - case object.ObjEncodingInt: + switch oType { + case object.ObjTypeInt: // Convert int64 to string for concatenation currentValueStr = strconv.FormatInt(obj.Value.(int64), 10) - case object.ObjEncodingEmbStr, object.ObjEncodingRaw: + case object.ObjTypeString: // Use the string value directly currentValueStr = obj.Value.(string) - case object.ObjEncodingByteArray: + case object.ObjTypeByteArray: val, ok := obj.Value.(*ByteArray) if !ok { return "", diceerrors.ErrWrongTypeOperation diff --git a/internal/eval/type_string_test.go b/internal/eval/type_string_test.go index 9ba597b46..0fc2bf33a 100644 --- a/internal/eval/type_string_test.go +++ b/internal/eval/type_string_test.go @@ -1,14 +1,15 @@ package eval import ( - "github.com/dicedb/dice/internal/object" "testing" + "github.com/dicedb/dice/internal/object" + "github.com/dicedb/dice/internal/server/utils" ) -// TestDeduceTypeEncoding tests the deduceTypeEncoding function using table-driven tests. -func TestDeduceTypeEncoding(t *testing.T) { +// TestDeduceType tests the deduceType function using table-driven tests. +func TestDeduceType(t *testing.T) { tests := []struct { name string input string @@ -19,39 +20,34 @@ func TestDeduceTypeEncoding(t *testing.T) { name: "Integer string", input: "123", wantType: object.ObjTypeInt, - wantEnc: object.ObjEncodingInt, }, { name: "Short string", input: "short string", wantType: object.ObjTypeString, - wantEnc: object.ObjEncodingEmbStr, }, { name: "Long string", input: "this is a very long string that exceeds the maximum length for EMBSTR encoding", wantType: object.ObjTypeString, - wantEnc: object.ObjEncodingRaw, }, { name: "Empty string", input: utils.EmptyStr, wantType: object.ObjTypeString, - wantEnc: object.ObjEncodingEmbStr, }, { name: "Boundary length string", input: "this string is exactly forty-four characters long", wantType: object.ObjTypeString, - wantEnc: object.ObjEncodingRaw, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gotType, gotEnc := deduceTypeEncoding(tt.input) - if gotType != tt.wantType || gotEnc != tt.wantEnc { - t.Errorf("deduceTypeEncoding(%q) = (%v, %v), want (%v, %v)", tt.input, gotType, gotEnc, tt.wantType, tt.wantEnc) + gotType := deduceType(tt.input) + if gotType != tt.wantType { + t.Errorf("deduceType(%q) = (%v), want (%v)", tt.input, gotType, tt.wantType) } }) } diff --git a/internal/object/deep_copy.go b/internal/object/deep_copy.go index bbff08bd8..18a10b73d 100644 --- a/internal/object/deep_copy.go +++ b/internal/object/deep_copy.go @@ -10,7 +10,7 @@ type DeepCopyable interface { func (obj *Obj) DeepCopy() *Obj { newObj := &Obj{ - TypeEncoding: obj.TypeEncoding, + Type: obj.Type, LastAccessedAt: obj.LastAccessedAt, } @@ -19,7 +19,7 @@ func (obj *Obj) DeepCopy() *Obj { newObj.Value = copier.DeepCopy() } else { // Handle types that are not DeepCopyable - sourceType, _ := ExtractTypeEncoding(obj) + sourceType := ExtractType(obj) switch sourceType { case ObjTypeString: sourceValue := obj.Value.(string) diff --git a/internal/object/object.go b/internal/object/object.go index 797a0f518..63b6b0c30 100644 --- a/internal/object/object.go +++ b/internal/object/object.go @@ -8,7 +8,7 @@ package object // // Fields: // -// - TypeEncoding: A uint8 field used to store the encoding type of the object. This +// - Type: A uint8 field used to store the type of the object. This // helps in identifying how the object is encoded or serialized (e.g., as a string, // number, or more complex type). It is crucial for determining how the object should // be interpreted or processed when retrieved from storage. @@ -18,14 +18,14 @@ package object // freshness of the object and can be used for cache expiry or eviction policies. // in DiceDB we use 32 bits due to Go's lack of native support for bitfields, // and to simplify management by not combining -// `TypeEncoding` and `LastAccessedAt` into a single integer. +// `Type` and `LastAccessedAt` into a single integer. // // - Value: An `interface{}` type that holds the actual data of the object. This could // represent any type of data, allowing flexibility to store different kinds of // objects (e.g., strings, numbers, complex data structures like lists or maps). type Obj struct { - // TypeEncoding holds the encoding type of the object (e.g., string, int, complex structure) - TypeEncoding uint8 + // Type holds the type of the object (e.g., string, int, complex structure) + Type uint8 // LastAccessedAt stores the last access timestamp of the object. // It helps track when the object was last accessed and may be used for cache eviction or freshness tracking. @@ -72,39 +72,17 @@ type InternalObj struct { ExDuration int64 } -var ObjTypeString uint8 = 0 << 4 - -var ObjEncodingRaw uint8 = 0 -var ObjEncodingInt uint8 = 1 -var ObjEncodingEmbStr uint8 = 8 - -var ObjTypeByteList uint8 = 1 << 4 -var ObjEncodingDeque uint8 = 4 - -var ObjTypeBitSet uint8 = 2 << 4 // 00100000 -var ObjEncodingBF uint8 = 2 // 00000010 - -var ObjTypeJSON uint8 = 3 << 4 // 00110000 -var ObjEncodingJSON uint8 = 0 - -var ObjTypeByteArray uint8 = 4 << 4 // 01000000 -var ObjEncodingByteArray uint8 = 4 - -var ObjTypeInt uint8 = 5 << 4 // 01010000 - -var ObjTypeSet uint8 = 6 << 4 // 01010000 -var ObjEncodingSetInt uint8 = 11 -var ObjEncodingSetStr uint8 = 12 - -var ObjEncodingHashMap uint8 = 6 -var ObjTypeHashMap uint8 = 7 << 4 - -var ObjTypeSortedSet uint8 = 8 << 4 -var ObjEncodingBTree uint8 = 8 - -var ObjTypeCountMinSketch uint8 = 9 << 4 -var ObjEncodingMatrix uint8 = 9 - -func ExtractTypeEncoding(obj *Obj) (e1, e2 uint8) { - return obj.TypeEncoding & 0b11110000, obj.TypeEncoding & 0b00001111 +var ObjTypeString uint8 = 0 +var ObjTypeJSON uint8 = 3 +var ObjTypeByteArray uint8 = 4 +var ObjTypeInt uint8 = 5 +var ObjTypeSet uint8 = 6 +var ObjTypeHashMap uint8 = 7 +var ObjTypeSortedSet uint8 = 8 +var ObjTypeCountMinSketch uint8 = 9 +var ObjTypeBF uint8 = 10 +var ObjTypeDequeue uint8 = 11 + +func ExtractType(obj *Obj) (e1 uint8) { + return obj.Type } diff --git a/internal/object/typeencoding.go b/internal/object/typeencoding.go index 619aa8d6d..b8f677066 100644 --- a/internal/object/typeencoding.go +++ b/internal/object/typeencoding.go @@ -6,33 +6,15 @@ import ( diceerrors "github.com/dicedb/dice/internal/errors" ) -func GetType(te uint8) uint8 { - return (te >> 4) << 4 -} - -func GetEncoding(te uint8) uint8 { - return te & 0b00001111 -} - -func AssertType(te, t uint8) error { - if GetType(te) != t { +func AssertTypeWithError(te, t uint8) error { + if te != t { return errors.New("WRONGTYPE Operation against a key holding the wrong kind of value") } return nil } -func AssertEncoding(te, e uint8) error { - if GetEncoding(te) != e { - return errors.New("the operation is not permitted on this encoding") - } - return nil -} - -func AssertTypeAndEncoding(typeEncoding, expectedType, expectedEncoding uint8) []byte { - if err := AssertType(typeEncoding, expectedType); err != nil { - return diceerrors.NewErrWithMessage(diceerrors.WrongKeyTypeErr) - } - if err := AssertEncoding(typeEncoding, expectedEncoding); err != nil { +func AssertType(_type, expectedType uint8) []byte { + if err := AssertTypeWithError(_type, expectedType); err != nil { return diceerrors.NewErrWithMessage(diceerrors.WrongKeyTypeErr) } return nil diff --git a/internal/sql/executerbechmark_test.go b/internal/sql/executerbechmark_test.go index 082087212..61b4b00c5 100644 --- a/internal/sql/executerbechmark_test.go +++ b/internal/sql/executerbechmark_test.go @@ -29,7 +29,7 @@ func generateBenchmarkData(count int, store *dstore.Store) { for i := 0; i < count; i++ { key := fmt.Sprintf("k%d", i) value := fmt.Sprintf("v%d", i) - data[key] = store.NewObj(value, -1, object.ObjTypeString, object.ObjEncodingRaw) + data[key] = store.NewObj(value, -1, object.ObjTypeString) } store.PutAll(data) } @@ -302,7 +302,7 @@ func generateBenchmarkJSONData(b *testing.B, count int, json string, store *dsto b.Fatalf("Failed to unmarshal JSON: %v", err) } - data[key] = store.NewObj(jsonValue, -1, object.ObjTypeJSON, object.ObjEncodingJSON) + data[key] = store.NewObj(jsonValue, -1, object.ObjTypeJSON) } store.PutAll(data) } diff --git a/internal/sql/executor.go b/internal/sql/executor.go index 9b8e51957..c85758d27 100644 --- a/internal/sql/executor.go +++ b/internal/sql/executor.go @@ -117,7 +117,7 @@ func ExecuteQuery(query *DSQLQuery, store common.ITable[string, *object.Obj]) ([ func MarshalResultIfJSON(row *QueryResultRow) error { // if the row contains JSON field then convert the json object into string representation so it can be encoded // before being returned to the client - if object.GetEncoding(row.Value.TypeEncoding) == object.ObjEncodingJSON && object.GetType(row.Value.TypeEncoding) == object.ObjTypeJSON { + if row.Value.Type == object.ObjTypeJSON { marshaledData, err := sonic.MarshalString(row.Value.Value) if err != nil { return err @@ -333,11 +333,7 @@ func getExprValueAndType(expr sqlparser.Expr, row QueryResultRow, jsonPathCache } func isJSONField(expr *sqlparser.SQLVal, obj *object.Obj) bool { - if err := object.AssertEncoding(obj.TypeEncoding, object.ObjEncodingJSON); err != nil { - return false - } - - if err := object.AssertType(obj.TypeEncoding, object.ObjTypeJSON); err != nil { + if err := object.AssertType(obj.Type, object.ObjTypeJSON); err != nil { return false } diff --git a/internal/sql/executor_test.go b/internal/sql/executor_test.go index 9e1978527..2dd52d798 100644 --- a/internal/sql/executor_test.go +++ b/internal/sql/executor_test.go @@ -279,7 +279,7 @@ func setupJSON(t *testing.T, store *dstore.Store, dataset []keyValue) { t.Fatalf("Failed to unmarshal value: %v", err) } - store.Put(data.key, store.NewObj(jsonValue, -1, object.ObjTypeJSON, object.ObjEncodingJSON)) + store.Put(data.key, store.NewObj(jsonValue, -1, object.ObjTypeJSON)) } } diff --git a/internal/store/store.go b/internal/store/store.go index 0c38aa295..5c1f46297 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -84,10 +84,10 @@ func ResetStore(store *Store) *Store { return store } -func (store *Store) NewObj(value interface{}, expDurationMs int64, oType, oEnc uint8) *object.Obj { +func (store *Store) NewObj(value interface{}, expDurationMs int64, oType uint8) *object.Obj { obj := &object.Obj{ Value: value, - TypeEncoding: oType | oEnc, + Type: oType, LastAccessedAt: getCurrentClock(), } if expDurationMs >= 0 {