diff --git a/ChangeLog b/ChangeLog index 44629c8..c96a717 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ * IMPROVE: adjust RecvChanSize based on `sender.count` or `scan.key_number` if target redis type is cluster. * IMPROVE: remove some useless variables in conf like `heartbeat`, `ncpu`. + * IMPROVE: print inner error message from redigo driver return message. 2019-08-09 Alibaba Cloud. * VERSION: 1.6.16 * BUGFIX: big key in `rump` mode all expired. diff --git a/src/redis-shake/common/command.go b/src/redis-shake/common/command.go index d7b7ab1..97ef810 100644 --- a/src/redis-shake/common/command.go +++ b/src/redis-shake/common/command.go @@ -10,6 +10,11 @@ import ( "strings" ) +const ( + ReplayString = "string" + ReplayInt64s = "int64s" +) + type ClusterNodeInfo struct { Id string Address string @@ -172,4 +177,18 @@ func GetAllClusterNode(client redigo.Conn, role string, choose string) ([]string } return result, nil +} + +func WrapCommand(tp string, reply interface{}, err error) (interface{}, error) { + if err != nil { + return nil, fmt.Errorf("inner error: %v", err) + } + switch tp { + case ReplayString: + return redigo.Strings(reply, err) + case ReplayInt64s: + return redigo.Int64s(reply, err) + default: + return nil, fmt.Errorf("command type[%v] not support", tp) + } } \ No newline at end of file diff --git a/src/redis-shake/rump.go b/src/redis-shake/rump.go index 247ec64..ce28efb 100644 --- a/src/redis-shake/rump.go +++ b/src/redis-shake/rump.go @@ -483,19 +483,24 @@ func (dre *dbRumperExecutor) doFetch(db int) error { log.Debugf("dbRumper[%v] executor[%v] scan key: %v", dre.rumperId, dre.executorId, key) dre.sourceClient.Send("DUMP", key) } - dumps, err := redis.Strings(dre.sourceClient.Do("")) + + reply, err := dre.sourceClient.Do("") + dumpsRet, err := utils.WrapCommand(utils.ReplayString, reply, err) if err != nil && err != redis.ErrNil { return fmt.Errorf("do dump with failed[%v]", err) } + dumps := dumpsRet.([]string) // pipeline ttl for _, key := range keys { dre.sourceClient.Send("PTTL", key) } - pttls, err := redis.Int64s(dre.sourceClient.Do("")) + reply, err = dre.sourceClient.Do("") + pttlsRet, err := utils.WrapCommand(utils.ReplayInt64s, reply, err) if err != nil && err != redis.ErrNil { return fmt.Errorf("do ttl with failed[%v]", err) } + pttls := pttlsRet.([]int64) dre.stat.rCommands.Add(int64(len(keys))) for i, k := range keys {