File tree Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 11package cmd
22
33import (
4+ "context"
45 "log"
56 "os"
67
@@ -26,14 +27,25 @@ to quickly create a Cobra application.`,
2627 config .LoadConfig ()
2728 cfg := config .GetConfig ()
2829
29- rdb := redis .NewClient (& redis.Options {
30- Addr : cfg .Addr ,
31- Password : cfg .Password ,
32- DB : cfg .DB ,
33- })
30+ var rdb * redis.Client
31+ switch cfg .Mode {
32+ case "sentinel" :
33+ rdb = redis .NewFailoverClient (& redis.FailoverOptions {
34+ MasterName : cfg .MasterName ,
35+ SentinelAddrs : cfg .SentinelAddrs ,
36+ Password : cfg .SentinelPassword ,
37+ })
38+ default :
39+ rdb = redis .NewClient (& redis.Options {
40+ Addr : cfg .Addr ,
41+ Password : cfg .Password ,
42+ DB : cfg .DB ,
43+ })
44+ }
3445
35- if rdb == nil {
36- log .Fatal ("start failed: cannot connect to redis" )
46+ _ , err := rdb .Ping (context .Background ()).Result ()
47+ if err != nil {
48+ log .Fatal ("connect to redis failed: " , err )
3749 }
3850
3951 p := tea .NewProgram (tui .New (rdb ), tea .WithAltScreen ())
Original file line number Diff line number Diff line change @@ -18,9 +18,17 @@ import (
1818
1919// Config represents the main config for the application.
2020type Config struct {
21+ Mode string `mapstructure:"mode"`
22+
23+ // client
2124 Addr string `mapstructure:"addr"`
2225 Password string `mapstructure:"password"`
2326 DB int `mapstructure:"db"`
27+
28+ // sentinel
29+ MasterName string `mapstructure:"master_name"`
30+ SentinelAddrs []string `mapstructure:"sentinel_addrs"`
31+ SentinelPassword string `mapstructure:"sentinel_password"`
2432}
2533
2634// LoadConfig loads a users config and creates the config if it does not exist.
You can’t perform that action at this time.
0 commit comments