From b797b4f016aa60dc7877ac85cbc8d5aa590e97bb Mon Sep 17 00:00:00 2001 From: suxb201 Date: Tue, 27 Sep 2022 18:39:24 +0800 Subject: [PATCH] add rdbTypeModule2 support --- internal/rdb/types/interface.go | 28 +++++++++-------------- internal/rdb/types/module2.go | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 internal/rdb/types/module2.go diff --git a/internal/rdb/types/interface.go b/internal/rdb/types/interface.go index b6e5942..7d9fb3d 100644 --- a/internal/rdb/types/interface.go +++ b/internal/rdb/types/interface.go @@ -2,7 +2,6 @@ package types import ( "github.com/alibaba/RedisShake/internal/log" - "github.com/alibaba/RedisShake/internal/rdb/structure" "io" ) @@ -48,6 +47,13 @@ const ( rdbTypeStreamListpacks2 = 19 // RDB_TYPE_STREAM_LISTPACKS2 moduleTypeNameCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" + + rdbModuleOpcodeEOF = 0 // End of module value. + rdbModuleOpcodeSINT = 1 // Signed integer. + rdbModuleOpcodeUINT = 2 // Unsigned integer. + rdbModuleOpcodeFLOAT = 3 // Float. + rdbModuleOpcodeDOUBLE = 4 // Double. + rdbModuleOpcodeSTRING = 5 // String. ) type RedisCmd []string @@ -55,7 +61,7 @@ type RedisCmd []string // RedisObject is interface for a redis object type RedisObject interface { LoadFromBuffer(rd io.Reader, key string, typeByte byte) - Rewrite() []RedisCmd // TODO big key + Rewrite() []RedisCmd } func ParseObject(rd io.Reader, typeByte byte, key string) RedisObject { @@ -85,21 +91,9 @@ func ParseObject(rd io.Reader, typeByte byte, key string) RedisObject { o.LoadFromBuffer(rd, key, typeByte) return o case rdbTypeModule, rdbTypeModule2: // module - if typeByte == rdbTypeModule { - log.Panicf("module type is not supported") - } - moduleId := structure.ReadLength(rd) - moduleName := moduleTypeNameByID(moduleId) - switch moduleName { - case "exhash---": - log.Panicf("exhash module is not supported") - case "exstrtype": - log.Panicf("exstrtype module is not supported") - case "tair-json": - log.Panicf("tair-json module is not supported") - default: - log.Panicf("unknown module type: %s", moduleName) - } + o := new(ModuleObject) + o.LoadFromBuffer(rd, key, typeByte) + return o } log.Panicf("unknown type byte: %d", typeByte) return nil diff --git a/internal/rdb/types/module2.go b/internal/rdb/types/module2.go new file mode 100644 index 0000000..26ab46e --- /dev/null +++ b/internal/rdb/types/module2.go @@ -0,0 +1,40 @@ +package types + +import ( + "github.com/alibaba/RedisShake/internal/log" + "github.com/alibaba/RedisShake/internal/rdb/structure" + "io" +) + +type ModuleObject struct { +} + +func (o *ModuleObject) LoadFromBuffer(rd io.Reader, key string, typeByte byte) { + if typeByte == rdbTypeModule { + log.Panicf("module type with version 1 is not supported, key=[%s]", key) + } + moduleId := structure.ReadLength(rd) + moduleName := moduleTypeNameByID(moduleId) + opcode := structure.ReadByte(rd) + for opcode != rdbModuleOpcodeEOF { + switch opcode { + case rdbModuleOpcodeSINT: + case rdbModuleOpcodeUINT: + structure.ReadLength(rd) + case rdbModuleOpcodeFLOAT: + structure.ReadFloat(rd) + case rdbModuleOpcodeDOUBLE: + structure.ReadDouble(rd) + case rdbModuleOpcodeSTRING: + structure.ReadString(rd) + default: + log.Panicf("unknown module opcode=[%d], module name=[%s]", opcode, moduleName) + } + opcode = structure.ReadByte(rd) + } +} + +func (o *ModuleObject) Rewrite() []RedisCmd { + log.Panicf("module Rewrite not implemented") + return nil +}