Skip to content

Commit

Permalink
supports RDBv7
Browse files Browse the repository at this point in the history
  • Loading branch information
spinlock committed Sep 28, 2016
1 parent 0690a8e commit df84a55
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
19 changes: 18 additions & 1 deletion pkg/rdb/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (

"github.com/CodisLabs/redis-port/pkg/libs/errors"
"github.com/CodisLabs/redis-port/pkg/rdb/digest"
"github.com/spinlock/rdb"
)

const Version = rdb.Version

type Loader struct {
*rdbReader
crc hash.Hash64
Expand All @@ -37,7 +40,7 @@ func (l *Loader) Header() error {
}
if version, err := strconv.ParseInt(string(header[5:]), 10, 64); err != nil {
return errors.Trace(err)
} else if version <= 0 || version > Version {
} else if version < 1 || version > Version {
return errors.Errorf("verify version, invalid RDB version number %d", version)
}
return nil
Expand Down Expand Up @@ -101,6 +104,20 @@ func (l *Loader) NextBinEntry() (*BinEntry, error) {
return nil, err
}
switch t {
case rdbFlagAux:
if _, err := l.readString(); err != nil {
return nil, err
}
if _, err := l.readString(); err != nil {
return nil, err
}
case rdbFlagResizeDB:
if _, err := l.readLength(); err != nil {
return nil, err
}
if _, err := l.readLength(); err != nil {
return nil, err
}
case rdbFlagExpiryMS:
ttlms, err := l.readUint64()
if err != nil {
Expand Down
27 changes: 18 additions & 9 deletions pkg/rdb/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ import (
"github.com/CodisLabs/redis-port/pkg/libs/errors"
)

const (
Version = 6
)

const (
rdbTypeString = 0
rdbTypeList = 1
rdbTypeSet = 2
rdbTypeZSet = 3
rdbTypeHash = 4

rdbTypeHashZipmap = 9
rdbTypeListZiplist = 10
rdbTypeSetIntset = 11
rdbTypeZSetZiplist = 12
rdbTypeHashZiplist = 13
rdbTypeHashZipmap = 9
rdbTypeListZiplist = 10
rdbTypeSetIntset = 11
rdbTypeZSetZiplist = 12
rdbTypeHashZiplist = 13
rdbTypeListQuicklist = 14

rdbFlagAux = 0xfa
rdbFlagResizeDB = 0xfb
rdbFlagExpiryMS = 0xfc
rdbFlagExpiry = 0xfd
rdbFlagSelectDB = 0xfe
Expand Down Expand Up @@ -135,6 +134,16 @@ func (r *rdbReader) readObjectValue(t byte) ([]byte, error) {
}
}
}
case rdbTypeListQuicklist:
if n, err := r.readLength(); err != nil {
return nil, err
} else {
for i := 0; i < int(n); i++ {
if _, err := r.readString(); err != nil {
return nil, err
}
}
}
}
return b.Bytes(), nil
}
Expand Down

0 comments on commit df84a55

Please sign in to comment.