Skip to content

Commit

Permalink
Revert linted files
Browse files Browse the repository at this point in the history
  • Loading branch information
svkaizoku committed Oct 2, 2024
1 parent c2bb5ab commit a005df7
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 87 deletions.
42 changes: 21 additions & 21 deletions internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,10 @@ var (
KeySpecs: KeySpecs{BeginIndex: 1},
}
hkeysCmdMeta = DiceCmdMeta{
Name: "HKEYS",
Info: `HKEYS command is used to retrieve all the keys(or field names) within a hash. Complexity is O(n) where n is the size of the hash.`,
Eval: evalHKEYS,
Arity: 1,
Name: "HKEYS",
Info: `HKEYS command is used to retrieve all the keys(or field names) within a hash. Complexity is O(n) where n is the size of the hash.`,
Eval: evalHKEYS,
Arity: 1,
KeySpecs: KeySpecs{BeginIndex: 1},
}
hsetnxCmdMeta = DiceCmdMeta{
Expand Down Expand Up @@ -911,27 +911,27 @@ var (
Arity: 3,
KeySpecs: KeySpecs{BeginIndex: 1},
}
dumpkeyCMmdMeta = DiceCmdMeta{
Name: "DUMP",
Info: `Serialize the value stored at key in a Redis-specific format and return it to the user.
dumpkeyCMmdMeta=DiceCmdMeta{
Name: "DUMP",
Info: `Serialize the value stored at key in a Redis-specific format and return it to the user.
The returned value can be synthesized back into a Redis key using the RESTORE command.`,
Eval: evalDUMP,
Arity: 1,
KeySpecs: KeySpecs{BeginIndex: 1},
Eval: evalDUMP,
Arity: 1,
KeySpecs: KeySpecs{BeginIndex: 1},
}
restorekeyCmdMeta = DiceCmdMeta{
Name: "RESTORE",
Info: `Serialize the value stored at key in a Redis-specific format and return it to the user.
restorekeyCmdMeta=DiceCmdMeta{
Name: "RESTORE",
Info: `Serialize the value stored at key in a Redis-specific format and return it to the user.
The returned value can be synthesized back into a Redis key using the RESTORE command.`,
Eval: evalRestore,
Arity: 2,
Eval: evalRestore,
Arity: 2,
KeySpecs: KeySpecs{BeginIndex: 1},
}
typeCmdMeta = DiceCmdMeta{
Name: "TYPE",
Info: `Returns the string representation of the type of the value stored at key. The different types that can be returned are: string, list, set, zset, hash and stream.`,
Eval: evalTYPE,
Arity: 1,
Name: "TYPE",
Info: `Returns the string representation of the type of the value stored at key. The different types that can be returned are: string, list, set, zset, hash and stream.`,
Eval: evalTYPE,
Arity: 1,

KeySpecs: KeySpecs{BeginIndex: 1},
}
Expand Down Expand Up @@ -1016,8 +1016,8 @@ func init() {
DiceCmds["PING"] = pingCmdMeta
DiceCmds["ECHO"] = echoCmdMeta
DiceCmds["AUTH"] = authCmdMeta
DiceCmds["DUMP"] = dumpkeyCMmdMeta
DiceCmds["RESTORE"] = restorekeyCmdMeta
DiceCmds["DUMP"]=dumpkeyCMmdMeta
DiceCmds["RESTORE"]=restorekeyCmdMeta
DiceCmds["SET"] = setCmdMeta
DiceCmds["GET"] = getCmdMeta
DiceCmds["MSET"] = msetCmdMeta
Expand Down
132 changes: 66 additions & 66 deletions internal/eval/dump_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ import (
)

func evalDUMP(args []string, store *dstore.Store) []byte {
if len(args) < 1 {
return diceerrors.NewErrArity("DUMP")
}
key := args[0]
obj := store.Get(key)
if obj == nil {
return diceerrors.NewErrWithFormattedMessage("nil")
}

serializedValue, err := rdbSerialize(obj)
if err != nil {
return diceerrors.NewErrWithMessage("serialization failed")
}
if len(args) < 1 {
return diceerrors.NewErrArity("DUMP")
}
key := args[0]
obj := store.Get(key)
if obj == nil {
return diceerrors.NewErrWithFormattedMessage("nil")
}
serializedValue, err := rdbSerialize(obj)
if err != nil {
return diceerrors.NewErrWithMessage("serialization failed")
}
encodedResult := base64.StdEncoding.EncodeToString(serializedValue)
return clientio.Encode(encodedResult, false)
return clientio.Encode(encodedResult, false)
}

func evalRestore(args []string, store *dstore.Store) []byte {
Expand All @@ -38,9 +38,9 @@ func evalRestore(args []string, store *dstore.Store) []byte {
}

key := args[0]
ttlStr := args[1]
ttlStr:=args[1]
ttl, _ := strconv.ParseInt(ttlStr, 10, 64)

encodedValue := args[2]
serializedData, err := base64.StdEncoding.DecodeString(encodedValue)
if err != nil {
Expand All @@ -52,23 +52,23 @@ func evalRestore(args []string, store *dstore.Store) []byte {
return diceerrors.NewErrWithMessage("deserialization failed: " + err.Error())
}

newobj := store.NewObj(obj.Value, ttl, obj.TypeEncoding, obj.TypeEncoding)
var keepttl = true
newobj:=store.NewObj(obj.Value,ttl,obj.TypeEncoding,obj.TypeEncoding)
var keepttl=true

if ttl > 0 {
if(ttl>0){
store.Put(key, newobj, dstore.WithKeepTTL(keepttl))
} else {
store.Put(key, obj)
}else{
store.Put(key,obj)
}

return clientio.RespOK
}

func rdbDeserialize(data []byte) (*object.Obj, error) {
if len(data) < 3 {
return nil, errors.New("insufficient data for deserialization")
}
objType := data[1]
objType := data[1]
switch objType {
case 0x00:
return readString(data[2:])
Expand Down Expand Up @@ -104,55 +104,55 @@ func readInt(data []byte) (*object.Obj, error) {
}

func rdbSerialize(obj *object.Obj) ([]byte, error) {
var buf bytes.Buffer
buf.WriteByte(0x09)

switch object.GetType(obj.TypeEncoding) {
case object.ObjTypeString:
str, ok := obj.Value.(string)
if !ok {
return nil, errors.New("invalid string value")
}
buf.WriteByte(0x00)
if err := writeString(&buf, str); err != nil {
return nil, err
}

case object.ObjTypeInt:
intVal, ok := obj.Value.(int64)
if !ok {
return nil, errors.New("invalid integer value")
}
buf.WriteByte(0xC0)
writeInt(&buf, intVal)

default:
return nil, errors.New("unsupported object type")
}

buf.WriteByte(0xFF) // End marker

return appendChecksum(buf.Bytes()), nil
var buf bytes.Buffer
buf.WriteByte(0x09)

switch object.GetType(obj.TypeEncoding) {
case object.ObjTypeString:
str, ok := obj.Value.(string)
if !ok {
return nil, errors.New("invalid string value")
}
buf.WriteByte(0x00)
if err := writeString(&buf, str); err != nil {
return nil, err
}

case object.ObjTypeInt:
intVal, ok := obj.Value.(int64)
if !ok {
return nil, errors.New("invalid integer value")
}
buf.WriteByte(0xC0)
writeInt(&buf, intVal);

default:
return nil, errors.New("unsupported object type")
}

buf.WriteByte(0xFF) // End marker

return appendChecksum(buf.Bytes()), nil
}

func writeString(buf *bytes.Buffer, str string) error {
strLen := uint32(len(str))
if err := binary.Write(buf, binary.BigEndian, strLen); err != nil {
return err
}
buf.WriteString(str)
return nil
strLen := uint32(len(str))
if err := binary.Write(buf, binary.BigEndian, strLen); err != nil {
return err
}
buf.WriteString(str)
return nil
}

func writeInt(buf *bytes.Buffer, intVal int64) {
tempBuf := make([]byte, 8)
binary.BigEndian.PutUint64(tempBuf, uint64(intVal))
buf.Write(tempBuf)
func writeInt(buf *bytes.Buffer, intVal int64){
tempBuf := make([]byte, 8)
binary.BigEndian.PutUint64(tempBuf, uint64(intVal))
buf.Write(tempBuf)
}

func appendChecksum(data []byte) []byte {
checksum := crc64.Checksum(data, crc64.MakeTable(crc64.ECMA))
checksumBuf := make([]byte, 8)
binary.BigEndian.PutUint64(checksumBuf, checksum)
return append(data, checksumBuf...)
checksum := crc64.Checksum(data, crc64.MakeTable(crc64.ECMA))
checksumBuf := make([]byte, 8)
binary.BigEndian.PutUint64(checksumBuf, checksum)
return append(data, checksumBuf...)
}
5 changes: 5 additions & 0 deletions internal/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -4151,6 +4151,8 @@ func evalJSONNUMINCRBY(args []string, store *dstore.Store) []byte {
return clientio.Encode(resultString, false)
}



// evalJSONOBJKEYS retrieves the keys of a JSON object stored at path specified.
// It takes two arguments: the key where the JSON document is stored, and an optional JSON path.
// It returns a list of keys from the object at the specified path or an error if the path is invalid.
Expand Down Expand Up @@ -4252,6 +4254,8 @@ func evalTYPE(args []string, store *dstore.Store) []byte {

return clientio.Encode(typeStr, true)
}


// evalGETRANGE returns the substring of the string value stored at key, determined by the offsets start and end
// The offsets are zero-based and can be negative values to index from the end of the string
//
Expand Down Expand Up @@ -4683,3 +4687,4 @@ func evalHINCRBYFLOAT(args []string, store *dstore.Store) []byte {

return clientio.Encode(numkey, false)
}

0 comments on commit a005df7

Please sign in to comment.