diff --git a/command.go b/command.go index ed597c6..248625e 100644 --- a/command.go +++ b/command.go @@ -693,8 +693,8 @@ func (cmd *ZSliceCmd) readReply(cn *pool.Conn) error { type ScanCmd struct { baseCmd - cursor int64 page []string + cursor uint64 } func NewScanCmd(args ...interface{}) *ScanCmd { @@ -709,14 +709,12 @@ func (cmd *ScanCmd) reset() { cmd.err = nil } -// TODO: swap return values - -func (cmd *ScanCmd) Val() (int64, []string) { - return cmd.cursor, cmd.page +func (cmd *ScanCmd) Val() (keys []string, cursor uint64) { + return cmd.page, cmd.cursor } -func (cmd *ScanCmd) Result() (int64, []string, error) { - return cmd.cursor, cmd.page, cmd.err +func (cmd *ScanCmd) Result() (keys []string, cursor uint64, err error) { + return cmd.page, cmd.cursor, cmd.err } func (cmd *ScanCmd) String() string { diff --git a/commands.go b/commands.go index 8ff6dc5..48a59f6 100644 --- a/commands.go +++ b/commands.go @@ -318,7 +318,7 @@ func (c *commandable) Type(key string) *StatusCmd { return cmd } -func (c *commandable) Scan(cursor int64, match string, count int64) Scanner { +func (c *commandable) Scan(cursor uint64, match string, count int64) Scanner { args := []interface{}{"SCAN", cursor} if match != "" { args = append(args, "MATCH", match) @@ -334,7 +334,7 @@ func (c *commandable) Scan(cursor int64, match string, count int64) Scanner { } } -func (c *commandable) SScan(key string, cursor int64, match string, count int64) Scanner { +func (c *commandable) SScan(key string, cursor uint64, match string, count int64) Scanner { args := []interface{}{"SSCAN", key, cursor} if match != "" { args = append(args, "MATCH", match) @@ -350,7 +350,7 @@ func (c *commandable) SScan(key string, cursor int64, match string, count int64) } } -func (c *commandable) HScan(key string, cursor int64, match string, count int64) Scanner { +func (c *commandable) HScan(key string, cursor uint64, match string, count int64) Scanner { args := []interface{}{"HSCAN", key, cursor} if match != "" { args = append(args, "MATCH", match) @@ -366,7 +366,7 @@ func (c *commandable) HScan(key string, cursor int64, match string, count int64) } } -func (c *commandable) ZScan(key string, cursor int64, match string, count int64) Scanner { +func (c *commandable) ZScan(key string, cursor uint64, match string, count int64) Scanner { args := []interface{}{"ZSCAN", key, cursor} if match != "" { args = append(args, "MATCH", match) diff --git a/commands_test.go b/commands_test.go index d1b00d9..8f27974 100644 --- a/commands_test.go +++ b/commands_test.go @@ -590,10 +590,10 @@ var _ = Describe("Commands", func() { Expect(set.Err()).NotTo(HaveOccurred()) } - cursor, keys, err := client.Scan(0, "", 0).Result() + keys, cursor, err := client.Scan(0, "", 0).Result() Expect(err).NotTo(HaveOccurred()) - Expect(cursor > 0).To(Equal(true)) - Expect(len(keys) > 0).To(Equal(true)) + Expect(keys).NotTo(BeEmpty()) + Expect(cursor).NotTo(BeZero()) }) It("should SScan", func() { @@ -602,10 +602,10 @@ var _ = Describe("Commands", func() { Expect(sadd.Err()).NotTo(HaveOccurred()) } - cursor, keys, err := client.SScan("myset", 0, "", 0).Result() + keys, cursor, err := client.SScan("myset", 0, "", 0).Result() Expect(err).NotTo(HaveOccurred()) - Expect(cursor > 0).To(Equal(true)) - Expect(len(keys) > 0).To(Equal(true)) + Expect(keys).NotTo(BeEmpty()) + Expect(cursor).NotTo(BeZero()) }) It("should HScan", func() { @@ -614,10 +614,10 @@ var _ = Describe("Commands", func() { Expect(sadd.Err()).NotTo(HaveOccurred()) } - cursor, keys, err := client.HScan("myhash", 0, "", 0).Result() + keys, cursor, err := client.HScan("myhash", 0, "", 0).Result() Expect(err).NotTo(HaveOccurred()) - Expect(cursor > 0).To(Equal(true)) - Expect(len(keys) > 0).To(Equal(true)) + Expect(keys).NotTo(BeEmpty()) + Expect(cursor).NotTo(BeZero()) }) It("should ZScan", func() { @@ -626,10 +626,10 @@ var _ = Describe("Commands", func() { Expect(sadd.Err()).NotTo(HaveOccurred()) } - cursor, keys, err := client.ZScan("myset", 0, "", 0).Result() + keys, cursor, err := client.ZScan("myset", 0, "", 0).Result() Expect(err).NotTo(HaveOccurred()) - Expect(cursor > 0).To(Equal(true)) - Expect(len(keys) > 0).To(Equal(true)) + Expect(keys).NotTo(BeEmpty()) + Expect(cursor).NotTo(BeZero()) }) }) diff --git a/example_test.go b/example_test.go index abac6af..4ab22f1 100644 --- a/example_test.go +++ b/example_test.go @@ -138,12 +138,12 @@ func ExampleClient_Scan() { } } - var cursor int64 + var cursor uint64 var n int for { var keys []string var err error - cursor, keys, err = client.Scan(cursor, "", 10).Result() + keys, cursor, err = client.Scan(cursor, "", 10).Result() if err != nil { panic(err) } diff --git a/parser.go b/parser.go index 4d8fee1..7a7b6f3 100644 --- a/parser.go +++ b/parser.go @@ -399,7 +399,7 @@ func readReply(cn *pool.Conn, p multiBulkParser) (interface{}, error) { return nil, fmt.Errorf("redis: can't parse %.100q", line) } -func readScanReply(cn *pool.Conn) ([]string, int64, error) { +func readScanReply(cn *pool.Conn) ([]string, uint64, error) { n, err := readArrayHeader(cn) if err != nil { return nil, 0, err @@ -413,7 +413,7 @@ func readScanReply(cn *pool.Conn) ([]string, int64, error) { return nil, 0, err } - cursor, err := strconv.ParseInt(bytesToString(b), 10, 64) + cursor, err := strconv.ParseUint(bytesToString(b), 10, 64) if err != nil { return nil, 0, err }