forked from mirror/redis
Merge pull request #347 from flisky/master
fix iterator for hscan/sscan/zscan
This commit is contained in:
commit
1324657ba9
|
@ -52,7 +52,11 @@ func (it *ScanIterator) Next() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch next page.
|
// Fetch next page.
|
||||||
|
if it.ScanCmd._args[0] == "scan" {
|
||||||
it.ScanCmd._args[1] = it.ScanCmd.cursor
|
it.ScanCmd._args[1] = it.ScanCmd.cursor
|
||||||
|
} else {
|
||||||
|
it.ScanCmd._args[2] = it.ScanCmd.cursor
|
||||||
|
}
|
||||||
it.ScanCmd.reset()
|
it.ScanCmd.reset()
|
||||||
it.client.process(it.ScanCmd)
|
it.client.process(it.ScanCmd)
|
||||||
if it.ScanCmd.Err() != nil {
|
if it.ScanCmd.Err() != nil {
|
||||||
|
|
|
@ -21,6 +21,16 @@ var _ = Describe("ScanIterator", func() {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hashKey = "K_HASHTEST"
|
||||||
|
var hashSeed = func(n int) error {
|
||||||
|
pipe := client.Pipeline()
|
||||||
|
for i := 1; i <= n; i++ {
|
||||||
|
pipe.HSet(hashKey, fmt.Sprintf("K%02d", i), "x").Err()
|
||||||
|
}
|
||||||
|
_, err := pipe.Exec()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
client = redis.NewClient(redisOptions())
|
client = redis.NewClient(redisOptions())
|
||||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||||
|
@ -62,6 +72,20 @@ var _ = Describe("ScanIterator", func() {
|
||||||
Expect(vals).To(ContainElement("K71"))
|
Expect(vals).To(ContainElement("K71"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should hscan across multiple pages", func() {
|
||||||
|
Expect(hashSeed(71)).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
var vals []string
|
||||||
|
iter := client.HScan(hashKey, 0, "", 10).Iterator()
|
||||||
|
for iter.Next() {
|
||||||
|
vals = append(vals, iter.Val())
|
||||||
|
}
|
||||||
|
Expect(iter.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(vals).To(HaveLen(71 * 2))
|
||||||
|
Expect(vals).To(ContainElement("K01"))
|
||||||
|
Expect(vals).To(ContainElement("K71"))
|
||||||
|
})
|
||||||
|
|
||||||
It("should scan to page borders", func() {
|
It("should scan to page borders", func() {
|
||||||
Expect(seed(20)).NotTo(HaveOccurred())
|
Expect(seed(20)).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue