Class: TimeWindowDropCollector::Storage

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/time_window_drop_collector/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#grouping_count, #slice_milliseconds, #slice_start_timestamp, #timestamp, #timestamp_key, #timestamp_key_multi, #window_keys, #window_keys_multi

Constructor Details

#initialize(wrapper, window, slices) ⇒ Storage

Returns a new instance of Storage.



6
7
8
9
10
# File 'lib/time_window_drop_collector/storage.rb', line 6

def initialize( wrapper, window, slices )
  @wrapper = wrapper
  @window  = window
  @slices  = slices
end

Instance Attribute Details

#slicesObject (readonly)

Returns the value of attribute slices.



4
5
6
# File 'lib/time_window_drop_collector/storage.rb', line 4

def slices
  @slices
end

#windowObject (readonly)

Returns the value of attribute window.



4
5
6
# File 'lib/time_window_drop_collector/storage.rb', line 4

def window
  @window
end

#wrapperObject (readonly)

Returns the value of attribute wrapper.



4
5
6
# File 'lib/time_window_drop_collector/storage.rb', line 4

def wrapper
  @wrapper
end

Instance Method Details

#count(keys) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/time_window_drop_collector/storage.rb', line 22

def count( keys )
  return {} if keys.empty?

  window_keys = window_keys_multi( keys )
  keys_values = wrapper.get( window_keys )

  grouping_count( keys_values )
end

#decr(timestamp, keys, amount = 1) ⇒ Object



18
19
20
# File 'lib/time_window_drop_collector/storage.rb', line 18

def decr( timestamp, keys, amount=1 )
  wrapper.decr(timestamp_key_multi( keys, timestamp), window, amount)
end

#incr(keys, amount = 1) ⇒ Object



12
13
14
15
16
# File 'lib/time_window_drop_collector/storage.rb', line 12

def incr( keys, amount=1 )
  now = Time.now
  wrapper.incr( timestamp_key_multi( keys, now), window, amount )
  now
end