condense code

This commit is contained in:
magodo 2019-07-11 14:13:58 +08:00
parent c8d57032bc
commit bdeae91063

View File

@ -32,13 +32,12 @@ func (m *memoryStore) Dump() ([]*store.Record, error) {
d := v.r.Expiry d := v.r.Expiry
t := time.Since(v.c) t := time.Since(v.c)
if d > time.Duration(0) {
// expired // expired
if d > time.Duration(0) && t > d { if t > d {
continue continue
} }
// update expiry // update expiry
if d > time.Duration(0) {
v.r.Expiry -= t v.r.Expiry -= t
v.c = time.Now() v.c = time.Now()
} }
@ -63,12 +62,11 @@ func (m *memoryStore) Read(key string) (*store.Record, error) {
t := time.Since(v.c) t := time.Since(v.c)
// expired // expired
if d > time.Duration(0) && t > d { if d > time.Duration(0) {
if t > d {
return nil, store.ErrNotFound return nil, store.ErrNotFound
} }
// update expiry // update expiry
if d > time.Duration(0) {
v.r.Expiry -= t v.r.Expiry -= t
v.c = time.Now() v.c = time.Now()
} }