fix #67, hang on EXPIRE

This commit is contained in:
Josh Baker 2016-10-16 08:50:02 -07:00
parent bd2c25987a
commit 4630a78613
1 changed files with 30 additions and 27 deletions

View File

@ -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)
}
}