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

Method cmdInfo

osscluster.go:2327–2350  ·  view source on GitHub ↗

cmdInfo will fetch and cache the command policies after the first execution

(ctx context.Context, name string)

Source from the content-addressed store, hash-verified

2325
2326// cmdInfo will fetch and cache the command policies after the first execution
2327func (c *ClusterClient) cmdInfo(ctx context.Context, name string) *CommandInfo {
2328 // Use a separate context that won't be canceled to ensure command info lookup
2329 // doesn't fail due to original context cancellation
2330 cmdInfoCtx := c.context(ctx)
2331 if c.opt.ContextTimeoutEnabled && ctx != nil {
2332 // If context timeout is enabled, still use a reasonable timeout
2333 var cancel context.CancelFunc
2334 cmdInfoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
2335 defer cancel()
2336 }
2337
2338 cmdsInfo, err := c.cmdsInfoCache.Get(cmdInfoCtx)
2339 if err != nil {
2340 internal.Logger.Printf(cmdInfoCtx, "getting command info: %s", err)
2341 return nil
2342 }
2343
2344 info := cmdsInfo[name]
2345 if info == nil {
2346 internal.Logger.Printf(cmdInfoCtx, "info for cmd=%s not found", name)
2347 }
2348
2349 return info
2350}
2351
2352// cmdInfoPeek returns the cached CommandInfo for the named command without
2353// triggering a round-trip to Redis. It returns nil when the cache is cold.

Callers 5

cmdsAreReadOnlyMethod · 0.95
cmdNodeMethod · 0.95
extractCommandInfoMethod · 0.95
routeAndRunMethod · 0.95

Calls 4

contextMethod · 0.95
WithTimeoutMethod · 0.80
GetMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected