-
Notifications
You must be signed in to change notification settings - Fork 8
/
call.go
55 lines (45 loc) · 1.27 KB
/
call.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"errors"
"fmt"
"strings"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
// call host:port command arg arg .. arg
var callCommand = cli.Command{
Name: "call",
Usage: "run command in redis cluster.",
ArgsUsage: `host:port command arg arg .. arg`,
Description: `The call command for call cmd in every redis cluster node.`,
Action: func(context *cli.Context) error {
if context.NArg() < 2 {
fmt.Printf("Incorrect Usage.\n\n")
cli.ShowCommandHelp(context, "call")
logrus.Fatalf("Must provide \"host:port command\" for call command!")
}
rt := NewRedisTrib()
if err := rt.CallClusterCmd(context); err != nil {
return err
}
return nil
},
}
func (self *RedisTrib) CallClusterCmd(context *cli.Context) error {
var addr string
if addr = context.Args().Get(0); addr == "" {
return errors.New("please check host:port for call command")
}
if err := self.LoadClusterInfoFromNode(addr); err != nil {
return err
}
cmd := strings.ToUpper(context.Args().Get(1))
cmdArgs := ToInterfaceArray(context.Args()[2:])
logrus.Printf(">>> Calling %s %s", cmd, cmdArgs)
_, err := self.EachRunCommandAndPrint(cmd, cmdArgs...)
if err != nil {
logrus.Errorf("Command failed: %s", err)
return err
}
return nil
}