Skip to content

Commit e314cd9

Browse files
authored
Merge pull request #2356 from go-redis/fix/cursor-uint64
fix: read cursor as uint64
2 parents 31f6ce0 + b88bd93 commit e314cd9

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

command.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2694,11 +2694,11 @@ func (cmd *ScanCmd) readReply(rd *proto.Reader) error {
26942694
return err
26952695
}
26962696

2697-
cursor, err := rd.ReadInt()
2697+
cursor, err := rd.ReadUint()
26982698
if err != nil {
26992699
return err
27002700
}
2701-
cmd.cursor = uint64(cursor)
2701+
cmd.cursor = cursor
27022702

27032703
n, err := rd.ReadArrayLen()
27042704
if err != nil {

internal/proto/reader.go

+27
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,33 @@ func (r *Reader) ReadInt() (int64, error) {
319319
return 0, fmt.Errorf("redis: can't parse int reply: %.100q", line)
320320
}
321321

322+
func (r *Reader) ReadUint() (uint64, error) {
323+
line, err := r.ReadLine()
324+
if err != nil {
325+
return 0, err
326+
}
327+
switch line[0] {
328+
case RespInt, RespStatus:
329+
return util.ParseUint(line[1:], 10, 64)
330+
case RespString:
331+
s, err := r.readStringReply(line)
332+
if err != nil {
333+
return 0, err
334+
}
335+
return util.ParseUint([]byte(s), 10, 64)
336+
case RespBigInt:
337+
b, err := r.readBigInt(line)
338+
if err != nil {
339+
return 0, err
340+
}
341+
if !b.IsUint64() {
342+
return 0, fmt.Errorf("bigInt(%s) value out of range", b.String())
343+
}
344+
return b.Uint64(), nil
345+
}
346+
return 0, fmt.Errorf("redis: can't parse uint reply: %.100q", line)
347+
}
348+
322349
func (r *Reader) ReadFloat() (float64, error) {
323350
line, err := r.ReadLine()
324351
if err != nil {

0 commit comments

Comments
 (0)