Skip to content

Commit

Permalink
Expire values in Progressrus::Store::Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
fw42 committed Feb 13, 2015
1 parent 52d4509 commit eb5734e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/progressrus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def expired?(now: Time.now)
def persist(force: false)
stores.each do |store|
begin
store.persist(self, force: force)
store.persist(self, force: force, expires_at: expires_at)
rescue Progressrus::Store::BackendError => e
end
end
Expand Down
10 changes: 8 additions & 2 deletions lib/progressrus/store/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ def initialize(instance, prefix: "progressrus", interval: 1, now: Time.now)
@prefix = prefix
end

def persist(progress, now: Time.now, force: false)
def persist(progress, now: Time.now, force: false, expires_at: nil)
if outdated?(progress) || force
redis.hset(key(progress.scope), progress.id, progress.to_serializeable.to_json)
key_for_scope = key(progress.scope)

redis.pipelined do
redis.hset(key_for_scope, progress.id, progress.to_serializeable.to_json)
redis.expireat(key_for_scope, expires_at) if expires_at
end

@persisted_ats[progress.scope][progress.id] = now
end
rescue *BACKEND_EXCEPTIONS => e
Expand Down

0 comments on commit eb5734e

Please sign in to comment.