mirror of
https://github.com/redis/go-redis.git
synced 2025-04-17 20:17:02 +03:00
Create extractKeys function
This commit is contained in:
parent
711143687c
commit
249510cbb5
24
command.go
24
command.go
@ -119,6 +119,30 @@ func cmdString(cmd Cmder, val interface{}) string {
|
||||
return util.BytesToString(b)
|
||||
}
|
||||
|
||||
func extractKeys(cmd Cmder) []string {
|
||||
firstKeyPos := cmdFirstKeyPos(cmd)
|
||||
if firstKeyPos == -1 {
|
||||
return nil
|
||||
}
|
||||
internal.Logger.Printf(context.Background(), "firstKeyPos: %d", firstKeyPos)
|
||||
args := cmd.Args()
|
||||
keys := []string{}
|
||||
|
||||
switch cmd.Name() {
|
||||
case "MGET", "MSET":
|
||||
for i := int(firstKeyPos); i < len(args); i += 2 {
|
||||
keys = append(keys, cmd.stringArg(i))
|
||||
}
|
||||
|
||||
default:
|
||||
if int(firstKeyPos) < len(args) {
|
||||
keys = append(keys, cmd.stringArg(firstKeyPos))
|
||||
}
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
type baseCmd struct {
|
||||
|
2
redis.go
2
redis.go
@ -431,7 +431,7 @@ func (c *baseClient) _process(ctx context.Context, cmd Cmder, attempt int) (bool
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
panic(cmd.firstKeyPos())
|
||||
internal.Logger.Printf(ctx, "redis: keys in command %s", extractKeys(cmd))
|
||||
retryTimeout := uint32(0)
|
||||
if err := c.withConn(ctx, func(ctx context.Context, cn *pool.Conn) error {
|
||||
if err := cn.WithWriter(c.context(ctx), c.opt.WriteTimeout, func(wr *proto.Writer) error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user