forked from mirror/redis
Merge pull request #1357 from go-redis/fix/command-info
Fix/command info
This commit is contained in:
commit
10561b3aa4
|
@ -5,7 +5,6 @@ services:
|
|||
- redis-server
|
||||
|
||||
go:
|
||||
- 1.11.x
|
||||
- 1.12.x
|
||||
- 1.13.x
|
||||
- 1.14.x
|
||||
|
|
2
Makefile
2
Makefile
|
@ -14,7 +14,7 @@ bench: testdeps
|
|||
|
||||
testdata/redis:
|
||||
mkdir -p $@
|
||||
wget -qO- http://download.redis.io/releases/redis-5.0.7.tar.gz | tar xvz --strip-components=1 -C $@
|
||||
wget -qO- http://download.redis.io/redis-stable.tar.gz | tar xvz --strip-components=1 -C $@
|
||||
|
||||
testdata/redis/src/redis-server: testdata/redis
|
||||
cd $< && make all
|
||||
|
|
33
command.go
33
command.go
|
@ -2019,6 +2019,7 @@ type CommandInfo struct {
|
|||
Name string
|
||||
Arity int8
|
||||
Flags []string
|
||||
ACLFlags []string
|
||||
FirstKeyPos int8
|
||||
LastKeyPos int8
|
||||
StepCount int8
|
||||
|
@ -2071,8 +2072,14 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
|
|||
}
|
||||
|
||||
func commandInfoParser(rd *proto.Reader, n int64) (interface{}, error) {
|
||||
if n != 6 {
|
||||
return nil, fmt.Errorf("redis: got %d elements in COMMAND reply, wanted 6", n)
|
||||
const numArgRedis5 = 6
|
||||
const numArgRedis6 = 7
|
||||
|
||||
switch n {
|
||||
case numArgRedis5, numArgRedis6:
|
||||
// continue
|
||||
default:
|
||||
return nil, fmt.Errorf("redis: got %d elements in COMMAND reply, wanted 7", n)
|
||||
}
|
||||
|
||||
var cmd CommandInfo
|
||||
|
@ -2132,6 +2139,28 @@ func commandInfoParser(rd *proto.Reader, n int64) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if n == numArgRedis5 {
|
||||
return &cmd, nil
|
||||
}
|
||||
|
||||
_, err = rd.ReadReply(func(rd *proto.Reader, n int64) (interface{}, error) {
|
||||
cmd.ACLFlags = make([]string, n)
|
||||
for i := 0; i < len(cmd.ACLFlags); i++ {
|
||||
switch s, err := rd.ReadString(); {
|
||||
case err == Nil:
|
||||
cmd.ACLFlags[i] = ""
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
cmd.ACLFlags[i] = s
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &cmd, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,10 @@ var _ = Describe("Commands", func() {
|
|||
pipe.Auth(ctx, "")
|
||||
return nil
|
||||
})
|
||||
Expect(err).To(MatchError("ERR Client sent AUTH, but no password is set"))
|
||||
Expect(cmds[0].Err()).To(MatchError("ERR Client sent AUTH, but no password is set"))
|
||||
Expect(cmds[1].Err()).To(MatchError("ERR Client sent AUTH, but no password is set"))
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("ERR AUTH"))
|
||||
Expect(cmds[0].Err().Error()).To(ContainSubstring("ERR AUTH"))
|
||||
Expect(cmds[1].Err().Error()).To(ContainSubstring("ERR AUTH"))
|
||||
|
||||
stats := client.PoolStats()
|
||||
Expect(stats.Hits).To(Equal(uint32(1)))
|
||||
|
|
|
@ -261,14 +261,18 @@ var _ = Describe("races", func() {
|
|||
Expect(n).To(Equal(int64(N)))
|
||||
})
|
||||
|
||||
It("should BLPop", func() {
|
||||
PIt("should BLPop", func() {
|
||||
var received uint32
|
||||
|
||||
wg := performAsync(C, func(id int) {
|
||||
for {
|
||||
v, err := client.BLPop(ctx, 3*time.Second, "list").Result()
|
||||
if err != nil {
|
||||
if err == redis.Nil {
|
||||
break
|
||||
}
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
Expect(v).To(Equal([]string{"list", "hello"}))
|
||||
atomic.AddUint32(&received, 1)
|
||||
}
|
||||
|
@ -282,7 +286,7 @@ var _ = Describe("races", func() {
|
|||
})
|
||||
|
||||
wg.Wait()
|
||||
Expect(received).To(Equal(uint32(C * N)))
|
||||
Expect(atomic.LoadUint32(&received)).To(Equal(uint32(C * N)))
|
||||
})
|
||||
|
||||
It("should WithContext", func() {
|
||||
|
|
|
@ -183,7 +183,8 @@ var _ = Describe("Redis Ring", func() {
|
|||
ring = redis.NewRing(opts)
|
||||
|
||||
err := ring.Ping(ctx).Err()
|
||||
Expect(err).To(MatchError("ERR Client sent AUTH, but no password is set"))
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("ERR AUTH"))
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue