| 348 | } |
| 349 | |
| 350 | func (c *Client) refreshClusterNodes(ctx context.Context) (bool, error) { |
| 351 | if !c.clusterDiscoveryEnabled() { |
| 352 | return false, nil |
| 353 | } |
| 354 | if ctx == nil { |
| 355 | ctx = context.Background() |
| 356 | } |
| 357 | cmd, errClient := c.commandClient() |
| 358 | if errClient != nil { |
| 359 | return false, errClient |
| 360 | } |
| 361 | raw, errDo := cmd.Do(ctx, "CLUSTER", "NODES").Text() |
| 362 | if errDo != nil { |
| 363 | return false, errDo |
| 364 | } |
| 365 | |
| 366 | nodes, errParse := parseClusterNodesPayload([]byte(raw)) |
| 367 | if errParse != nil { |
| 368 | return false, errParse |
| 369 | } |
| 370 | if len(nodes) == 0 { |
| 371 | return false, nil |
| 372 | } |
| 373 | |
| 374 | c.mu.Lock() |
| 375 | defer c.mu.Unlock() |
| 376 | c.clusterNodes = nodes |
| 377 | c.reconnectFailures = 0 |
| 378 | return c.switchToNodeLocked(nodes[0]), nil |
| 379 | } |
| 380 | |
| 381 | func parseClusterNodesPayload(raw []byte) ([]clusterNode, error) { |
| 382 | var envelope clusterNodesEnvelope |