-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_ttl.go
54 lines (41 loc) · 1.05 KB
/
db_ttl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package storager
import "time"
func (db *DB) rmExpire(t *Batch, dataType byte, key []byte) (int64, error) {
mk := db.expEncodeMetaKey(dataType, key)
v, err := db.IKV.Get(mk)
if err != nil {
return 0, err
} else if v == nil {
return 0, nil
}
when, err2 := Int64(v, nil)
if err2 != nil {
return 0, err2
}
tk := db.expEncodeTimeKey(dataType, key, when)
t.Delete(mk)
t.Delete(tk)
RemoveDBExpKeyStats(db.store, db.stats, mk, tk, when)
return 1, nil
}
func (db *DB) ttl(dataType byte, key []byte) (t int64, err error) {
mk := db.expEncodeMetaKey(dataType, key)
if t, err = Int64(db.IKV.Get(mk)); err != nil || t == 0 {
t = -1
} else {
t -= time.Now().Unix()
if t <= 0 {
t = -1
}
// if t == -1 : to remove ????
}
return t, err
}
func (db *DB) expireAt(t *Batch, dataType byte, key []byte, when int64) {
mk := db.expEncodeMetaKey(dataType, key)
tk := db.expEncodeTimeKey(dataType, key, when)
t.Put(tk, mk)
t.Put(mk, PutInt64(when))
AddDBExpKeyStats(db.store, db.stats, mk, tk, when)
db.ttlChecker.setNextCheckTime(when, false)
}