setCommandValue sets the aggregated value on a command using the enum-based approach
(cmd Cmder, value interface{})
| 512 | |
| 513 | // setCommandValue sets the aggregated value on a command using the enum-based approach |
| 514 | func (c *ClusterClient) setCommandValue(cmd Cmder, value interface{}) error { |
| 515 | // If value is nil, it might mean ExtractCommandValue couldn't extract the value |
| 516 | // but the command might have executed successfully. In this case, don't set an error. |
| 517 | if value == nil { |
| 518 | // ExtractCommandValue returned nil - this means the command type is not supported |
| 519 | // in the aggregation flow. This is a programming error, not a runtime error. |
| 520 | if cmd.Err() != nil { |
| 521 | // Command already has an error, preserve it |
| 522 | return cmd.Err() |
| 523 | } |
| 524 | // Command executed successfully but we can't extract/set the aggregated value |
| 525 | // This indicates the command type needs to be added to ExtractCommandValue |
| 526 | return fmt.Errorf("redis: cannot aggregate command %s: unsupported command type %d", |
| 527 | cmd.Name(), cmd.GetCmdType()) |
| 528 | } |
| 529 | |
| 530 | switch cmd.GetCmdType() { |
| 531 | case CmdTypeGeneric: |
| 532 | if c, ok := cmd.(*Cmd); ok { |
| 533 | c.SetVal(value) |
| 534 | } |
| 535 | case CmdTypeString: |
| 536 | if c, ok := cmd.(*StringCmd); ok { |
| 537 | if v, ok := value.(string); ok { |
| 538 | c.SetVal(v) |
| 539 | } |
| 540 | } |
| 541 | case CmdTypeInt: |
| 542 | if c, ok := cmd.(*IntCmd); ok { |
| 543 | if v, ok := value.(int64); ok { |
| 544 | c.SetVal(v) |
| 545 | } else if v, ok := value.(float64); ok { |
| 546 | c.SetVal(int64(v)) |
| 547 | } |
| 548 | } |
| 549 | case CmdTypeBool: |
| 550 | if c, ok := cmd.(*BoolCmd); ok { |
| 551 | if v, ok := value.(bool); ok { |
| 552 | c.SetVal(v) |
| 553 | } |
| 554 | } |
| 555 | case CmdTypeFloat: |
| 556 | if c, ok := cmd.(*FloatCmd); ok { |
| 557 | if v, ok := value.(float64); ok { |
| 558 | c.SetVal(v) |
| 559 | } |
| 560 | } |
| 561 | case CmdTypeStringSlice: |
| 562 | if c, ok := cmd.(*StringSliceCmd); ok { |
| 563 | if v, ok := value.([]string); ok { |
| 564 | c.SetVal(v) |
| 565 | } |
| 566 | } |
| 567 | case CmdTypeIntSlice: |
| 568 | if c, ok := cmd.(*IntSliceCmd); ok { |
| 569 | if v, ok := value.([]int64); ok { |
| 570 | c.SetVal(v) |
| 571 | } else if v, ok := value.([]float64); ok { |
no test coverage detected