(client *Client, sentinel string, onSubscribed func())
| 107 | } |
| 108 | |
| 109 | func (s *Sentinel) subscribeCommand(client *Client, sentinel string, |
| 110 | onSubscribed func()) error { |
| 111 | var channels = []interface{}{"+switch-master"} |
| 112 | go func() { |
| 113 | client.Send("SUBSCRIBE", channels...) |
| 114 | client.Flush() |
| 115 | }() |
| 116 | for _, sub := range channels { |
| 117 | values, err := redigo.Values(client.Receive()) |
| 118 | if err != nil { |
| 119 | return errors.Trace(err) |
| 120 | } else if len(values) != 3 { |
| 121 | return errors.Errorf("invalid response = %v", values) |
| 122 | } |
| 123 | s, err := redigo.Strings(values[:2], nil) |
| 124 | if err != nil || s[0] != "subscribe" || s[1] != sub.(string) { |
| 125 | return errors.Errorf("invalid response = %v", values) |
| 126 | } |
| 127 | } |
| 128 | onSubscribed() |
| 129 | for { |
| 130 | values, err := redigo.Values(client.Receive()) |
| 131 | if err != nil { |
| 132 | return errors.Trace(err) |
| 133 | } else if len(values) < 2 { |
| 134 | return errors.Errorf("invalid response = %v", values) |
| 135 | } |
| 136 | message, err := redigo.Strings(values, nil) |
| 137 | if err != nil || message[0] != "message" { |
| 138 | return errors.Errorf("invalid response = %v", values) |
| 139 | } |
| 140 | s.printf("sentinel-[%s] subscribe event %v", sentinel, message) |
| 141 | |
| 142 | switch message[1] { |
| 143 | case "+switch-master": |
| 144 | if len(message) != 3 { |
| 145 | return errors.Errorf("invalid response = %v", values) |
| 146 | } |
| 147 | var params = strings.SplitN(message[2], " ", 2) |
| 148 | if len(params) != 2 { |
| 149 | return errors.Errorf("invalid response = %v", values) |
| 150 | } |
| 151 | _, yes := s.isSameProduct(params[0]) |
| 152 | if yes { |
| 153 | return nil |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | func (s *Sentinel) subscribeDispatch(ctx context.Context, sentinel string, timeout time.Duration, |
| 160 | onSubscribed func()) (bool, error) { |
no test coverage detected