mirror of https://github.com/tidwall/tile38.git
fix #67, hang on EXPIRE
This commit is contained in:
parent
bd2c25987a
commit
4630a78613
|
@ -56,10 +56,11 @@ func (c *Controller) getExpires(key, id string) (at time.Time, ok bool) {
|
|||
// per second.
|
||||
func (c *Controller) backgroundExpiring() {
|
||||
for {
|
||||
ok := func() bool {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.stopBackgroundExpiring {
|
||||
c.mu.Unlock()
|
||||
return
|
||||
return false
|
||||
}
|
||||
// Only excute for leaders. Followers should ignore.
|
||||
if c.config.FollowHost == "" {
|
||||
|
@ -68,9 +69,7 @@ func (c *Controller) backgroundExpiring() {
|
|||
for id, at := range m {
|
||||
if now.After(at) {
|
||||
// issue a DEL command
|
||||
c.mu.Lock()
|
||||
c.statsExpired++
|
||||
c.mu.Unlock()
|
||||
msg := &server.Message{}
|
||||
msg.Values = resp.MultiBulkValue("del", key, id).Array()
|
||||
msg.Command = "del"
|
||||
|
@ -87,7 +86,11 @@ func (c *Controller) backgroundExpiring() {
|
|||
}
|
||||
}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
return true
|
||||
}()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Second / 5)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue