Merge pull request #347 from flisky/master

fix iterator for hscan/sscan/zscan
This commit is contained in:
Vladimir Mihailenco 2016-08-04 17:44:18 +03:00 committed by GitHub
commit 1324657ba9
2 changed files with 29 additions and 1 deletions

View File

@ -52,7 +52,11 @@ func (it *ScanIterator) Next() bool {
}
// Fetch next page.
if it.ScanCmd._args[0] == "scan" {
it.ScanCmd._args[1] = it.ScanCmd.cursor
} else {
it.ScanCmd._args[2] = it.ScanCmd.cursor
}
it.ScanCmd.reset()
it.client.process(it.ScanCmd)
if it.ScanCmd.Err() != nil {

View File

@ -21,6 +21,16 @@ var _ = Describe("ScanIterator", func() {
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() {
client = redis.NewClient(redisOptions())
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
@ -62,6 +72,20 @@ var _ = Describe("ScanIterator", func() {
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() {
Expect(seed(20)).NotTo(HaveOccurred())