Merge pull request #2356 from go-redis/fix/cursor-uint64

fix: read cursor as uint64
This commit is contained in:
Vladimir Mihailenco 2023-01-20 15:15:43 +02:00 committed by GitHub
commit e314cd9846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -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 {

View File

@ -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 {