Skip to content

Commit

Permalink
chore: Remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
suxb201 committed Feb 1, 2024
1 parent 8949bfa commit b931f44
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmd/redis-shake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
utils.SetPprofPort()
luaRuntime := function.New(config.Opt.Function)

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// create reader
Expand Down
17 changes: 8 additions & 9 deletions internal/rdb/types/tairhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ import (
)

type TairHashObject struct {
dictSize string
key string
rd io.Reader
cmdC chan RedisCmd
rd io.Reader
cmdC chan RedisCmd
}

func (o *TairHashObject) LoadFromBuffer(rd io.Reader, key string, typeByte byte) {
o.dictSize = structure.ReadModuleUnsigned(rd)
o.key = structure.ReadModuleString(rd)
// `key` and `typeByte` are not used
o.rd = rd
o.cmdC = make(chan RedisCmd)
}
Expand All @@ -26,17 +23,19 @@ func (o *TairHashObject) Rewrite() <-chan RedisCmd {
cmdC := o.cmdC
go func() {
defer close(o.cmdC)
size, _ := strconv.Atoi(o.dictSize)
dictSizeStr := structure.ReadModuleUnsigned(rd)
key := structure.ReadModuleString(rd)
size, _ := strconv.Atoi(dictSizeStr)
for i := 0; i < size; i++ {
skey := structure.ReadModuleString(rd)
version := structure.ReadModuleUnsigned(rd)
expireText := structure.ReadModuleUnsigned(rd)
fieldValue := structure.ReadModuleString(rd)
expire, _ := strconv.Atoi(expireText)
if expire == 0 {
cmdC <- RedisCmd{"EXHSET", o.key, skey, fieldValue}
cmdC <- RedisCmd{"EXHSET", key, skey, fieldValue}
} else {
cmdC <- RedisCmd{"EXHSET", o.key, skey, fieldValue,
cmdC <- RedisCmd{"EXHSET", key, skey, fieldValue,
"ABS", version,
"PXAT", expireText}
}
Expand Down
14 changes: 5 additions & 9 deletions internal/rdb/types/tairzset.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ import (
)

type TairZsetObject struct {
key string
length string
scoreNum string
rd io.Reader
cmdC chan RedisCmd
key string
rd io.Reader
cmdC chan RedisCmd
}

func (o *TairZsetObject) LoadFromBuffer(rd io.Reader, key string, typeByte byte) {
o.key = key
o.length = structure.ReadModuleUnsigned(rd)
o.scoreNum = structure.ReadModuleUnsigned(rd)
o.rd = rd
o.cmdC = make(chan RedisCmd)
}
Expand All @@ -29,8 +25,8 @@ func (o *TairZsetObject) Rewrite() <-chan RedisCmd {
cmdC := o.cmdC
go func() {
defer close(cmdC)
length, _ := strconv.Atoi(o.length)
scoreNum, _ := strconv.Atoi(o.scoreNum)
length, _ := strconv.Atoi(structure.ReadModuleUnsigned(rd))
scoreNum, _ := strconv.Atoi(structure.ReadModuleUnsigned(rd))
for i := 0; i < length; i++ {
key := structure.ReadModuleString(rd)
var values []string
Expand Down

0 comments on commit b931f44

Please sign in to comment.