From df84a5560929647f46cb24d562141bc85c0637c9 Mon Sep 17 00:00:00 2001 From: spinlock Date: Wed, 28 Sep 2016 12:13:25 +0800 Subject: [PATCH] supports RDBv7 --- pkg/rdb/loader.go | 19 ++++++++++++++++++- pkg/rdb/reader.go | 27 ++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/pkg/rdb/loader.go b/pkg/rdb/loader.go index e71e442..19d9355 100644 --- a/pkg/rdb/loader.go +++ b/pkg/rdb/loader.go @@ -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 @@ -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 @@ -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 { diff --git a/pkg/rdb/reader.go b/pkg/rdb/reader.go index 31d2d6f..6af3056 100644 --- a/pkg/rdb/reader.go +++ b/pkg/rdb/reader.go @@ -13,10 +13,6 @@ import ( "github.com/CodisLabs/redis-port/pkg/libs/errors" ) -const ( - Version = 6 -) - const ( rdbTypeString = 0 rdbTypeList = 1 @@ -24,12 +20,15 @@ const ( 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 @@ -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 }