MCPcopy
hub / github.com/redis/go-redis / cmdFirstKeyPosWithInfo

Function cmdFirstKeyPosWithInfo

command.go:285–319  ·  view source on GitHub ↗

cmdFirstKeyPosWithInfo returns the first key position in a command's args (0 if none). Uses CommandInfo.FirstKeyPos when available (via cache peek, no network call), falling back to a hardcoded table. eval/evalsha variants are resolved from the runtime numkeys arg.

(cmd Cmder, info *CommandInfo)

Source from the content-addressed store, hash-verified

283// Uses CommandInfo.FirstKeyPos when available (via cache peek, no network call), falling
284// back to a hardcoded table. eval/evalsha variants are resolved from the runtime numkeys arg.
285func cmdFirstKeyPosWithInfo(cmd Cmder, info *CommandInfo) int {
286 if pos := cmd.firstKeyPos(); pos != 0 {
287 return int(pos)
288 }
289
290 name := cmd.Name()
291
292 // first check if the command is keyless
293 if _, ok := keylessCommands[name]; ok {
294 return 0
295 }
296
297 switch name {
298 case "eval", "evalsha", "eval_ro", "evalsha_ro":
299 if cmd.stringArg(2) != "0" {
300 return 3
301 }
302
303 return 0
304 case "memory":
305 // https://github.com/redis/redis/issues/7493
306 if cmd.stringArg(1) == "usage" {
307 return 2
308 }
309 // CommandInfo (if available) gives the correct answer
310 // otherwise the hardcoded fallback applies.
311 }
312
313 // Use CommandInfo cache when warm (in-memory only, no extra round-trips).
314 if info != nil {
315 return int(info.FirstKeyPos)
316 }
317
318 return 1
319}
320
321func cmdString(cmd Cmder, val interface{}) string {
322 b := make([]byte, 0, 64)

Callers 8

cmdShardMethod · 0.85
slottedKeyedCommandsMethod · 0.85
cmdSlotMethod · 0.85
executeMultiShardMethod · 0.85
createAggregatorMethod · 0.85
hasKeysMethod · 0.85

Calls 3

firstKeyPosMethod · 0.65
NameMethod · 0.65
stringArgMethod · 0.65