mirror of https://github.com/go-redis/redis.git
commit
788a36eee7
11
iterator.go
11
iterator.go
|
@ -46,7 +46,8 @@ func (it *ScanIterator) Next() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return if there is more data to fetch.
|
for {
|
||||||
|
// Return if there is no more data to fetch.
|
||||||
if it.ScanCmd.cursor == 0 {
|
if it.ScanCmd.cursor == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -64,7 +65,13 @@ func (it *ScanIterator) Next() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
it.pos = 1
|
it.pos = 1
|
||||||
return len(it.ScanCmd.page) > 0
|
|
||||||
|
// Redis can occasionally return empty page
|
||||||
|
if len(it.ScanCmd.page) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Val returns the key/field at the current cursor position.
|
// Val returns the key/field at the current cursor position.
|
||||||
|
|
|
@ -21,6 +21,18 @@ var _ = Describe("ScanIterator", func() {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var extraSeed = func(n int, m int) error {
|
||||||
|
pipe := client.Pipeline()
|
||||||
|
for i := 1; i <= m; i++ {
|
||||||
|
pipe.Set(fmt.Sprintf("A%02d", i), "x", 0).Err()
|
||||||
|
}
|
||||||
|
for i := 1; i <= n; i++ {
|
||||||
|
pipe.Set(fmt.Sprintf("K%02d", i), "x", 0).Err()
|
||||||
|
}
|
||||||
|
_, err := pipe.Exec()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var hashKey = "K_HASHTEST"
|
var hashKey = "K_HASHTEST"
|
||||||
var hashSeed = func(n int) error {
|
var hashSeed = func(n int) error {
|
||||||
pipe := client.Pipeline()
|
pipe := client.Pipeline()
|
||||||
|
@ -110,4 +122,15 @@ var _ = Describe("ScanIterator", func() {
|
||||||
Expect(vals).To(HaveLen(13))
|
Expect(vals).To(HaveLen(13))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should scan with match across empty pages", func() {
|
||||||
|
Expect(extraSeed(2, 10)).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
var vals []string
|
||||||
|
iter := client.Scan(0, "K*", 1).Iterator()
|
||||||
|
for iter.Next() {
|
||||||
|
vals = append(vals, iter.Val())
|
||||||
|
}
|
||||||
|
Expect(iter.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(vals).To(HaveLen(2))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue