Class: MerryGoRound::Entry
- Inherits:
-
Object
- Object
- MerryGoRound::Entry
- Defined in:
- lib/merry_go_round/entry.rb
Instance Method Summary collapse
-
#initialize(key, increment = 1, timestamp = Time.now) ⇒ Entry
constructor
A new instance of Entry.
- #record! ⇒ Object
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, = 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 = 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 |