File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed
Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ type Jodis struct {
2222 data []byte
2323
2424 client models.Client
25+ online bool
2526 closed bool
2627
2728 watching bool
@@ -98,6 +99,13 @@ func (j *Jodis) Rewatch() (<-chan struct{}, error) {
9899}
99100
100101func (j * Jodis ) Start () {
102+ j .mu .Lock ()
103+ defer j .mu .Unlock ()
104+ if j .online {
105+ return
106+ }
107+ j .online = true
108+
101109 go func () {
102110 var delay = & DelayExp2 {
103111 Min : 1 , Max : 30 ,
Original file line number Diff line number Diff line change @@ -45,13 +45,13 @@ type Proxy struct {
4545
4646 lproxy net.Listener
4747 ladmin net.Listener
48- xjodis * Jodis
4948
5049 ha struct {
5150 monitor * redis.Sentinel
5251 masters map [int ]string
5352 servers []string
5453 }
54+ jodis * Jodis
5555}
5656
5757var ErrClosedProxy = errors .New ("use of closed proxy" )
@@ -151,7 +151,7 @@ func (s *Proxy) setup(config *Config) error {
151151 } else {
152152 s .model .JodisPath = models .JodisPath (config .ProductName , s .model .Token )
153153 }
154- s .xjodis = NewJodis (c , s .model )
154+ s .jodis = NewJodis (c , s .model )
155155 }
156156
157157 return nil
@@ -168,6 +168,9 @@ func (s *Proxy) Start() error {
168168 }
169169 s .online = true
170170 s .router .Start ()
171+ if s .jodis != nil {
172+ s .jodis .Start ()
173+ }
171174 return nil
172175}
173176
@@ -180,8 +183,8 @@ func (s *Proxy) Close() error {
180183 s .closed = true
181184 close (s .exit .C )
182185
183- if s .xjodis != nil {
184- s .xjodis .Close ()
186+ if s .jodis != nil {
187+ s .jodis .Close ()
185188 }
186189 if s .ladmin != nil {
187190 s .ladmin .Close ()
@@ -415,9 +418,6 @@ func (s *Proxy) serveProxy() {
415418 if d := s .config .BackendPingPeriod .Duration (); d != 0 {
416419 go s .keepAlive (d )
417420 }
418- if s .xjodis != nil {
419- s .xjodis .Start ()
420- }
421421
422422 select {
423423 case <- s .exit .C :
You can’t perform that action at this time.
0 commit comments