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

Method cmdsInfo

osscluster.go:2284–2324  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

2282}
2283
2284func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo, error) {
2285 // Try 3 random nodes.
2286 const nodeLimit = 3
2287
2288 addrs, err := c.nodes.Addrs()
2289 if err != nil {
2290 return nil, err
2291 }
2292
2293 var firstErr error
2294
2295 perm := rand.Perm(len(addrs))
2296 if len(perm) > nodeLimit {
2297 perm = perm[:nodeLimit]
2298 }
2299
2300 for _, idx := range perm {
2301 addr := addrs[idx]
2302 node, err := c.nodes.GetOrCreate(addr)
2303 if err != nil {
2304 if firstErr == nil {
2305 firstErr = err
2306 }
2307 continue
2308 }
2309
2310 info, err := node.Client.Command(ctx).Result()
2311 if err == nil {
2312 return info, nil
2313 }
2314
2315 if firstErr == nil {
2316 firstErr = err
2317 }
2318 }
2319
2320 if firstErr == nil {
2321 panic("not reached")
2322 }
2323 return nil, firstErr
2324}
2325
2326// cmdInfo will fetch and cache the command policies after the first execution
2327func (c *ClusterClient) cmdInfo(ctx context.Context, name string) *CommandInfo {

Callers

nothing calls this directly

Calls 4

AddrsMethod · 0.80
GetOrCreateMethod · 0.80
ResultMethod · 0.65
CommandMethod · 0.65

Tested by

no test coverage detected