Skip to content

Commit f0f314d

Browse files
committed
un-implent "SCAN COUNT" so cursors work as they should
1 parent ed06249 commit f0f314d

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

cmd_generic.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,8 @@ func (m *Miniredis) cmdScan(c *server.Peer, cmd string, args []string) {
649649

650650
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
651651
db := m.db(ctx.selectedDB)
652-
// We return _all_ (matched) keys every time.
652+
// We return _all_ (matched) keys every time, so that cursors work.
653+
// We ignore "COUNT", which is allowed according to the Redis docs.
653654
var keys []string
654655

655656
if opts.withType {
@@ -670,24 +671,27 @@ func (m *Miniredis) cmdScan(c *server.Peer, cmd string, args []string) {
670671
keys, _ = matchKeys(keys, opts.match)
671672
}
672673

673-
low := opts.cursor
674-
high := low + opts.count
675-
// validate high is correct
676-
if high > len(keys) || high == 0 {
677-
high = len(keys)
678-
}
679-
if opts.cursor > high {
680-
// invalid cursor
681-
c.WriteLen(2)
682-
c.WriteBulk("0") // no next cursor
683-
c.WriteLen(0) // no elements
684-
return
685-
}
686-
cursorValue := low + opts.count
687-
if cursorValue >= len(keys) {
688-
cursorValue = 0 // no next cursor
689-
}
690-
keys = keys[low:high]
674+
cursorValue := 0 // we don't use cursors
675+
/*
676+
low := opts.cursor
677+
high := low + opts.count
678+
// validate high is correct
679+
if high > len(keys) || high == 0 {
680+
high = len(keys)
681+
}
682+
if opts.cursor > high {
683+
// invalid cursor
684+
c.WriteLen(2)
685+
c.WriteBulk("0") // no next cursor
686+
c.WriteLen(0) // no elements
687+
return
688+
}
689+
cursorValue := low + opts.count
690+
if cursorValue >= len(keys) {
691+
cursorValue = 0 // no next cursor
692+
}
693+
keys = keys[low:high]
694+
*/
691695

692696
c.WriteLen(2)
693697
c.WriteBulk(fmt.Sprintf("%d", cursorValue))

0 commit comments

Comments
 (0)