gab-social/app/lib/activity_tracker.rb

34 lines
583 B
Ruby
Raw Normal View History

2019-07-02 08:10:25 +01:00
# frozen_string_literal: true
class ActivityTracker
EXPIRE_AFTER = 90.days.seconds
class << self
include Redisable
def increment(prefix)
key = [prefix, current_week].join(':')
redis.with do |conn|
conn.incrby(key, 1)
conn.expire(key, EXPIRE_AFTER)
end
2019-07-02 08:10:25 +01:00
end
def record(prefix, value)
key = [prefix, current_week].join(':')
redis.with do |conn|
conn.pfadd(key, value)
conn.expire(key, EXPIRE_AFTER)
end
2019-07-02 08:10:25 +01:00
end
private
def current_week
Time.zone.today.cweek
end
end
end