diff --git a/iterator.go b/iterator.go index e9dfbad9..0a3df063 100644 --- a/iterator.go +++ b/iterator.go @@ -52,7 +52,11 @@ func (it *ScanIterator) Next() bool { } // Fetch next page. - it.ScanCmd._args[1] = it.ScanCmd.cursor + 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 { diff --git a/iterator_test.go b/iterator_test.go index 327feeb5..f752f68c 100644 --- a/iterator_test.go +++ b/iterator_test.go @@ -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())