Skip to content

Commit 249510c

Browse files
committed
Create extractKeys function
1 parent 7111436 commit 249510c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

command.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,30 @@ func cmdString(cmd Cmder, val interface{}) string {
119119
return util.BytesToString(b)
120120
}
121121

122+
func extractKeys(cmd Cmder) []string {
123+
firstKeyPos := cmdFirstKeyPos(cmd)
124+
if firstKeyPos == -1 {
125+
return nil
126+
}
127+
internal.Logger.Printf(context.Background(), "firstKeyPos: %d", firstKeyPos)
128+
args := cmd.Args()
129+
keys := []string{}
130+
131+
switch cmd.Name() {
132+
case "MGET", "MSET":
133+
for i := int(firstKeyPos); i < len(args); i += 2 {
134+
keys = append(keys, cmd.stringArg(i))
135+
}
136+
137+
default:
138+
if int(firstKeyPos) < len(args) {
139+
keys = append(keys, cmd.stringArg(firstKeyPos))
140+
}
141+
}
142+
143+
return keys
144+
}
145+
122146
//------------------------------------------------------------------------------
123147

124148
type baseCmd struct {

redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ func (c *baseClient) _process(ctx context.Context, cmd Cmder, attempt int) (bool
431431
return false, err
432432
}
433433
}
434-
panic(cmd.firstKeyPos())
434+
internal.Logger.Printf(ctx, "redis: keys in command %s", extractKeys(cmd))
435435
retryTimeout := uint32(0)
436436
if err := c.withConn(ctx, func(ctx context.Context, cn *pool.Conn) error {
437437
if err := cn.WithWriter(c.context(ctx), c.opt.WriteTimeout, func(wr *proto.Writer) error {

0 commit comments

Comments
 (0)