2014-05-22 16:02:22 +04:00
|
|
|
package ledis
|
|
|
|
|
2014-06-03 11:40:10 +04:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (db *DB) FlushAll() (drop int64, err error) {
|
2014-05-22 16:02:22 +04:00
|
|
|
all := [...](func() (int64, error)){
|
2014-06-03 11:40:10 +04:00
|
|
|
db.Flush,
|
2014-05-22 16:02:22 +04:00
|
|
|
db.LFlush,
|
|
|
|
db.HFlush,
|
|
|
|
db.ZFlush}
|
|
|
|
|
|
|
|
for _, flush := range all {
|
|
|
|
if n, e := flush(); e != nil {
|
|
|
|
err = e
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
drop += n
|
|
|
|
}
|
|
|
|
}
|
2014-06-03 11:40:10 +04:00
|
|
|
|
2014-05-22 16:02:22 +04:00
|
|
|
return
|
|
|
|
}
|
2014-06-03 11:40:10 +04:00
|
|
|
|
|
|
|
func (db *DB) activeExpireCycle() {
|
|
|
|
eliminator := newEliminator(db)
|
|
|
|
eliminator.regRetireContext(kvExpType, db.kvTx, db.delete)
|
|
|
|
|
|
|
|
go func() {
|
2014-06-05 11:59:10 +04:00
|
|
|
tick := time.NewTicker(1 * time.Second)
|
2014-06-03 11:40:10 +04:00
|
|
|
for {
|
2014-06-05 11:59:10 +04:00
|
|
|
select {
|
|
|
|
case <-tick.C:
|
|
|
|
eliminator.active()
|
|
|
|
case <-db.l.quit:
|
|
|
|
break
|
|
|
|
}
|
2014-06-03 11:40:10 +04:00
|
|
|
}
|
2014-06-05 11:59:10 +04:00
|
|
|
|
|
|
|
tick.Stop()
|
2014-06-03 11:40:10 +04:00
|
|
|
}()
|
|
|
|
}
|