cmdInfo will fetch and cache the command policies after the first execution
(ctx context.Context, name string)
| 2325 | |
| 2326 | // cmdInfo will fetch and cache the command policies after the first execution |
| 2327 | func (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. |
no test coverage detected