forked from soarpenguin/redis-trib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fix.go
70 lines (61 loc) · 1.49 KB
/
fix.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"errors"
"fmt"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
// fix host:port
// --timeout <arg>
var fixCommand = cli.Command{
Name: "fix",
Usage: "fix the redis cluster.",
ArgsUsage: `host:port`,
Description: `The fix command for fix the redis cluster.`,
Flags: []cli.Flag{
cli.IntFlag{
Name: "timeout, t",
Value: MigrateDefaultTimeout,
Usage: `timeout for fix the redis cluster.`,
},
cli.StringFlag{
Name: "password, a",
Value: "",
Usage: `password, the default value is "".`,
},
cli.StringFlag{
Name: "password, a",
Value: "",
Usage: `password, the default value is ""`,
},
},
Action: func(context *cli.Context) error {
if context.NArg() != 1 {
fmt.Printf("Incorrect Usage.\n\n")
cli.ShowCommandHelp(context, "fix")
logrus.Fatalf("Must provide at least \"host:port\" for fix command!")
}
if context.String("password") != "" {
RedisPassword = context.String("password")
}
rt := NewRedisTrib()
if err := rt.FixClusterCmd(context); err != nil {
return err
}
return nil
},
}
func (rt *RedisTrib) FixClusterCmd(context *cli.Context) error {
var addr string
if addr = context.Args().Get(0); addr == "" {
return errors.New("please check host:port for fix command")
}
rt.SetFix(true)
timeout := context.Int("timeout")
rt.SetTimeout(timeout)
if err := rt.LoadClusterInfoFromNode(addr); err != nil {
return err
}
rt.CheckCluster(false)
return nil
}