Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified build.sh
100644 → 100755
Empty file.
54 changes: 54 additions & 0 deletions cases/hash_as_listpack_with_hfe.aof
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
*8
$5
HMSET
$12
listpack-hfe
$2
F1
$2
V1
$2
F3
$2
V3
$2
F2
$2
V2
*6
$10
HPEXPIREAT
$12
listpack-hfe
$13
2755484483878
$6
FIELDS
$1
1
$2
F3
*5
$8
HPERSIST
$12
listpack-hfe
$6
FIELDS
$1
1
$2
F2
*6
$10
HPEXPIREAT
$12
listpack-hfe
$13
2755482478325
$6
FIELDS
$1
1
$2
F1
3 changes: 3 additions & 0 deletions cases/hash_as_listpack_with_hfe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"db":0,"key":"listpack-hfe","size":316,"type":"hash","encoding":"listpackex","hash":{"F1":"V1","F2":"V2","F3":"V3"},"expire":{"F1":2755482478325,"F2":0,"F3":2755484483878}}
]
Binary file added cases/hash_as_listpack_with_hfe.rdb
Binary file not shown.
131 changes: 131 additions & 0 deletions cases/hash_with_hfe.aof
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
*18
$5
HMSET
$8
hash-hfe
$2
F4
$2
V4
$2
F7
$2
V7
$2
F8
$2
V8
$2
F2
$2
V2
$2
F5
$2
V5
$2
F3
$2
V3
$2
F1
$2
V1
$2
F6
$2
V6
*5
$8
HPERSIST
$8
hash-hfe
$6
FIELDS
$1
1
$2
F8
*6
$10
HPEXPIREAT
$8
hash-hfe
$13
2755483429282
$6
FIELDS
$1
1
$2
F2
*5
$8
HPERSIST
$8
hash-hfe
$6
FIELDS
$1
1
$2
F5
*6
$10
HPEXPIREAT
$8
hash-hfe
$13
2755484433842
$6
FIELDS
$1
1
$2
F3
*6
$10
HPEXPIREAT
$8
hash-hfe
$13
2755482424661
$6
FIELDS
$1
1
$2
F1
*5
$8
HPERSIST
$8
hash-hfe
$6
FIELDS
$1
1
$2
F6
*5
$8
HPERSIST
$8
hash-hfe
$6
FIELDS
$1
1
$2
F4
*5
$8
HPERSIST
$8
hash-hfe
$6
FIELDS
$1
1
$2
F7
3 changes: 3 additions & 0 deletions cases/hash_with_hfe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"db":0,"key":"hash-hfe","size":660,"type":"hash","encoding":"hashex","hash":{"F1":"V1","F2":"V2","F3":"V3","F4":"V4","F5":"V5","F6":"V6","F7":"V7","F8":"V8"},"expire":{"F1":2755482424661,"F2":2755483429282,"F3":2755484433842,"F4":0,"F5":0,"F6":0,"F7":0,"F8":0}}
]
Binary file added cases/hash_with_hfe.rdb
Binary file not shown.
76 changes: 56 additions & 20 deletions core/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/hdt3213/rdb/memprofiler"
"github.com/hdt3213/rdb/model"
"io"
"strconv"
"time"

"github.com/hdt3213/rdb/memprofiler"
"github.com/hdt3213/rdb/model"
)

// Decoder is an instance of rdb parsing process
Expand Down Expand Up @@ -87,27 +88,41 @@ const (
typeStreamListPacks2
typeSetListPack
typeStreamListPacks3
typeHashWithHfeRc // rdb 12 (only redis 7.4 rc)
typeHashListPackWithHfeRc // rdb 12 (only redis 7.4 rc)
typeHashWithHfe // since rdb 12 (redis 7.4)
typeHashListPackWithHfe // since rdb 12 (redis 7.4)
)

const (
EB_EXPIRE_TIME_MAX int64 = 0x0000FFFFFFFFFFFF
EB_EXPIRE_TIME_INVALID int64 = EB_EXPIRE_TIME_MAX + 1
HFE_MAX_ABS_TIME_MSEC int64 = EB_EXPIRE_TIME_MAX >> 2
)

var encodingMap = map[int]string{
typeString: model.StringEncoding,
typeList: model.ListEncoding,
typeSet: model.SetEncoding,
typeZset: model.ZSetEncoding,
typeHash: model.HashEncoding,
typeZset2: model.ZSet2Encoding,
typeHashZipMap: model.ZipMapEncoding,
typeListZipList: model.ZipListEncoding,
typeSetIntSet: model.IntSetEncoding,
typeZsetZipList: model.ZipListEncoding,
typeHashZipList: model.ZipListEncoding,
typeListQuickList: model.QuickListEncoding,
typeStreamListPacks: model.ListPackEncoding,
typeStreamListPacks2: model.ListPackEncoding,
typeHashListPack: model.ListPackEncoding,
typeZsetListPack: model.ListPackEncoding,
typeListQuickList2: model.QuickList2Encoding,
typeSetListPack: model.ListPackEncoding,
typeString: model.StringEncoding,
typeList: model.ListEncoding,
typeSet: model.SetEncoding,
typeZset: model.ZSetEncoding,
typeHash: model.HashEncoding,
typeZset2: model.ZSet2Encoding,
typeHashZipMap: model.ZipMapEncoding,
typeListZipList: model.ZipListEncoding,
typeSetIntSet: model.IntSetEncoding,
typeZsetZipList: model.ZipListEncoding,
typeHashZipList: model.ZipListEncoding,
typeListQuickList: model.QuickListEncoding,
typeStreamListPacks: model.ListPackEncoding,
typeStreamListPacks2: model.ListPackEncoding,
typeHashListPack: model.ListPackEncoding,
typeZsetListPack: model.ListPackEncoding,
typeListQuickList2: model.QuickList2Encoding,
typeSetListPack: model.ListPackEncoding,
typeHashWithHfeRc: model.HashExEncoding,
typeHashListPackWithHfeRc: model.ListPackExEncoding,
typeHashWithHfe: model.HashExEncoding,
typeHashListPackWithHfe: model.ListPackExEncoding,
}

// checkHeader checks whether input has valid RDB file header
Expand Down Expand Up @@ -311,6 +326,27 @@ func (dec *Decoder) readObject(flag byte, base *model.BaseObject) (model.RedisOb
BaseObject: base,
Members: set,
}, nil
case typeHashWithHfe, typeHashWithHfeRc:
hash, expire, err := dec.readHashMapEx(func() bool { return flag == typeHashWithHfeRc }())
if err != nil {
return nil, err
}
return &model.HashObject{
BaseObject: base,
Hash: hash,
FieldExpirations: expire,
}, nil
case typeHashListPackWithHfe, typeHashListPackWithHfeRc:
m, e, extra, err := dec.readListPackHashEx(func() bool { return flag == typeHashListPackWithHfeRc }())
if err != nil {
return nil, err
}
base.Extra = extra
return &model.HashObject{
BaseObject: base,
Hash: m,
FieldExpirations: e,
}, nil
}
return nil, fmt.Errorf("unknown type flag: %b", flag)
}
Expand Down
Loading