Class: MerryGoRound::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/merry_go_round/entry.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, increment = 1, timestamp = Time.now) ⇒ Entry

Returns a new instance of Entry.



3
4
5
6
7
8
9
10
# File 'lib/merry_go_round/entry.rb', line 3

def initialize(key, increment = 1, timestamp = Time.now)
  @key = key
  @increment = increment

  # Note, storing in the past isn't supported. If you set this to something the
  # aggregator has already run, the results are undefined.
  @timestamp = timestamp
end

Instance Method Details

#record!Object



12
13
14
15
16
17
18
# File 'lib/merry_go_round/entry.rb', line 12

def record!
  # Normalize time. Drop seconds and convert to UTC
  time = Time.at(@timestamp.to_i - @timestamp.sec).utc.to_i

  # Store in Redis
  redis.hincrby "entry-#{time.to_s}", @key, @increment
end