Skip to content

Commit

Permalink
Rebase on top of ttl.
Browse files Browse the repository at this point in the history
  • Loading branch information
chowchow316 committed Apr 14, 2017
1 parent 55d333c commit 570d6ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,10 @@ func (db *RedisDB) setUnion(keys []string) (setKey, error) {
// fastForward proceeds the current timestamp with duration, works as a time machine
func (db *RedisDB) fastForward(duration time.Duration) () {
for _, key := range db.allKeys() {
value, ok := db.expire[key]
value, ok := db.ttl[key]
if ok {
db.expire[key] = value - int(duration)
if db.expire[key] <= 0 {
db.ttl[key] = value - duration
if db.ttl[key] <= 0 {
db.del(key, true)
}
}
Expand Down
5 changes: 3 additions & 2 deletions miniredis.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ func (m *Miniredis) TotalConnectionCount() int {

// FastForward proceeds the time of selected db by duration.
func (m *Miniredis) FastForward(duration time.Duration) () {
db := m.db(m.selectedDB)
db.fastForward(duration)
for _, db := range m.dbs {
db.fastForward(duration)
}
}

// Dump returns a text version of the selected DB, usable for debugging.
Expand Down
2 changes: 1 addition & 1 deletion miniredis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestExpireWithFastForward(t *testing.T) {
ok(t, err)
s.Set("aap", "noot")
equals(t, []string{"aap"}, s.Keys())
s.SetExpire("aap", 10)
s.SetTTL("aap", 10)

s.FastForward(10)
equals(t, []string{}, s.Keys())
Expand Down

0 comments on commit 570d6ff

Please sign in to comment.