diff --git a/command.go b/command.go index 8c77c24d..fa909c12 100644 --- a/command.go +++ b/command.go @@ -2694,11 +2694,11 @@ func (cmd *ScanCmd) readReply(rd *proto.Reader) error { return err } - cursor, err := rd.ReadInt() + cursor, err := rd.ReadUint() if err != nil { return err } - cmd.cursor = uint64(cursor) + cmd.cursor = cursor n, err := rd.ReadArrayLen() if err != nil { diff --git a/internal/proto/reader.go b/internal/proto/reader.go index 1cf161a5..33dda4b2 100644 --- a/internal/proto/reader.go +++ b/internal/proto/reader.go @@ -319,6 +319,33 @@ func (r *Reader) ReadInt() (int64, error) { return 0, fmt.Errorf("redis: can't parse int reply: %.100q", line) } +func (r *Reader) ReadUint() (uint64, error) { + line, err := r.ReadLine() + if err != nil { + return 0, err + } + switch line[0] { + case RespInt, RespStatus: + return util.ParseUint(line[1:], 10, 64) + case RespString: + s, err := r.readStringReply(line) + if err != nil { + return 0, err + } + return util.ParseUint([]byte(s), 10, 64) + case RespBigInt: + b, err := r.readBigInt(line) + if err != nil { + return 0, err + } + if !b.IsUint64() { + return 0, fmt.Errorf("bigInt(%s) value out of range", b.String()) + } + return b.Uint64(), nil + } + return 0, fmt.Errorf("redis: can't parse uint reply: %.100q", line) +} + func (r *Reader) ReadFloat() (float64, error) { line, err := r.ReadLine() if err != nil {