forked from mirror/redis
Merge pull request #303 from go-redis/fix/scan-ret-values
Scan: swap return values and change cursor type.
This commit is contained in:
commit
033a4de2fb
12
command.go
12
command.go
|
@ -693,8 +693,8 @@ func (cmd *ZSliceCmd) readReply(cn *pool.Conn) error {
|
||||||
type ScanCmd struct {
|
type ScanCmd struct {
|
||||||
baseCmd
|
baseCmd
|
||||||
|
|
||||||
cursor int64
|
|
||||||
page []string
|
page []string
|
||||||
|
cursor uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewScanCmd(args ...interface{}) *ScanCmd {
|
func NewScanCmd(args ...interface{}) *ScanCmd {
|
||||||
|
@ -709,14 +709,12 @@ func (cmd *ScanCmd) reset() {
|
||||||
cmd.err = nil
|
cmd.err = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: swap return values
|
func (cmd *ScanCmd) Val() (keys []string, cursor uint64) {
|
||||||
|
return cmd.page, cmd.cursor
|
||||||
func (cmd *ScanCmd) Val() (int64, []string) {
|
|
||||||
return cmd.cursor, cmd.page
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *ScanCmd) Result() (int64, []string, error) {
|
func (cmd *ScanCmd) Result() (keys []string, cursor uint64, err error) {
|
||||||
return cmd.cursor, cmd.page, cmd.err
|
return cmd.page, cmd.cursor, cmd.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *ScanCmd) String() string {
|
func (cmd *ScanCmd) String() string {
|
||||||
|
|
|
@ -318,7 +318,7 @@ func (c *commandable) Type(key string) *StatusCmd {
|
||||||
return cmd
|
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}
|
args := []interface{}{"SCAN", cursor}
|
||||||
if match != "" {
|
if match != "" {
|
||||||
args = append(args, "MATCH", 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}
|
args := []interface{}{"SSCAN", key, cursor}
|
||||||
if match != "" {
|
if match != "" {
|
||||||
args = append(args, "MATCH", 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}
|
args := []interface{}{"HSCAN", key, cursor}
|
||||||
if match != "" {
|
if match != "" {
|
||||||
args = append(args, "MATCH", 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}
|
args := []interface{}{"ZSCAN", key, cursor}
|
||||||
if match != "" {
|
if match != "" {
|
||||||
args = append(args, "MATCH", match)
|
args = append(args, "MATCH", match)
|
||||||
|
|
|
@ -590,10 +590,10 @@ var _ = Describe("Commands", func() {
|
||||||
Expect(set.Err()).NotTo(HaveOccurred())
|
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(err).NotTo(HaveOccurred())
|
||||||
Expect(cursor > 0).To(Equal(true))
|
Expect(keys).NotTo(BeEmpty())
|
||||||
Expect(len(keys) > 0).To(Equal(true))
|
Expect(cursor).NotTo(BeZero())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should SScan", func() {
|
It("should SScan", func() {
|
||||||
|
@ -602,10 +602,10 @@ var _ = Describe("Commands", func() {
|
||||||
Expect(sadd.Err()).NotTo(HaveOccurred())
|
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(err).NotTo(HaveOccurred())
|
||||||
Expect(cursor > 0).To(Equal(true))
|
Expect(keys).NotTo(BeEmpty())
|
||||||
Expect(len(keys) > 0).To(Equal(true))
|
Expect(cursor).NotTo(BeZero())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should HScan", func() {
|
It("should HScan", func() {
|
||||||
|
@ -614,10 +614,10 @@ var _ = Describe("Commands", func() {
|
||||||
Expect(sadd.Err()).NotTo(HaveOccurred())
|
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(err).NotTo(HaveOccurred())
|
||||||
Expect(cursor > 0).To(Equal(true))
|
Expect(keys).NotTo(BeEmpty())
|
||||||
Expect(len(keys) > 0).To(Equal(true))
|
Expect(cursor).NotTo(BeZero())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should ZScan", func() {
|
It("should ZScan", func() {
|
||||||
|
@ -626,10 +626,10 @@ var _ = Describe("Commands", func() {
|
||||||
Expect(sadd.Err()).NotTo(HaveOccurred())
|
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(err).NotTo(HaveOccurred())
|
||||||
Expect(cursor > 0).To(Equal(true))
|
Expect(keys).NotTo(BeEmpty())
|
||||||
Expect(len(keys) > 0).To(Equal(true))
|
Expect(cursor).NotTo(BeZero())
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -138,12 +138,12 @@ func ExampleClient_Scan() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var cursor int64
|
var cursor uint64
|
||||||
var n int
|
var n int
|
||||||
for {
|
for {
|
||||||
var keys []string
|
var keys []string
|
||||||
var err error
|
var err error
|
||||||
cursor, keys, err = client.Scan(cursor, "", 10).Result()
|
keys, cursor, err = client.Scan(cursor, "", 10).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,7 +399,7 @@ func readReply(cn *pool.Conn, p multiBulkParser) (interface{}, error) {
|
||||||
return nil, fmt.Errorf("redis: can't parse %.100q", line)
|
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)
|
n, err := readArrayHeader(cn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
@ -413,7 +413,7 @@ func readScanReply(cn *pool.Conn) ([]string, int64, error) {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor, err := strconv.ParseInt(bytesToString(b), 10, 64)
|
cursor, err := strconv.ParseUint(bytesToString(b), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue