Class: Minuteman
- Inherits:
-
Object
- Object
- Minuteman
- Defined in:
- lib/minuteman.rb,
lib/minuteman/time_span.rb,
lib/minuteman/time_events.rb,
lib/minuteman/keys_methods.rb,
lib/minuteman/bit_operations.rb,
lib/minuteman/time_spans/day.rb,
lib/minuteman/time_spans/hour.rb,
lib/minuteman/time_spans/week.rb,
lib/minuteman/time_spans/year.rb,
lib/minuteman/time_spans/month.rb,
lib/minuteman/time_spans/minute.rb,
lib/minuteman/bit_operations/data.rb,
lib/minuteman/bit_operations/plain.rb,
lib/minuteman/bit_operations/result.rb,
lib/minuteman/bit_operations/operation.rb,
lib/minuteman/bit_operations/with_data.rb
Defined Under Namespace
Modules: BitOperations, KeysMethods, TimeEvents Classes: Day, Hour, Minute, Month, TimeSpan, Week, Year
Constant Summary collapse
- PREFIX =
"minuteman"
Instance Attribute Summary collapse
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
-
#events ⇒ Object
Public: List all the events given the minuteman namespace.
-
#initialize(options = {}) ⇒ Minuteman
constructor
Public: Initializes Minuteman.
-
#mark(event_name, ids, time = Time.now.utc) ⇒ Object
Public: Marks an id to a given event on a given time.
-
#operations ⇒ Object
Public: List all the operations executed in a given the minuteman namespace.
-
#reset_all ⇒ Object
Public: Resets all the used keys.
-
#reset_operations_cache ⇒ Object
Public: Resets the bit operation cache keys.
Constructor Details
Instance Attribute Details
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
21 22 23 |
# File 'lib/minuteman.rb', line 21 def redis @redis end |
Instance Method Details
#events ⇒ Object
Public: List all the events given the minuteman namespace
69 70 71 72 |
# File 'lib/minuteman.rb', line 69 def events keys = @redis.keys([PREFIX, "*", "????"].join("_")) keys.map { |key| key.split("_")[1] } end |
#mark(event_name, ids, time = Time.now.utc) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/minuteman.rb', line 56 def mark(event_name, ids, time = Time.now.utc) event_time = time.kind_of?(Time) ? time : Time.parse(time.to_s) time_events = TimeEvents.start(redis, event_name, event_time) @redis.multi do time_events.each do |event| Array(ids).each { |id| redis.setbit(event.key, id, 1) } end end end |
#operations ⇒ Object
Public: List all the operations executed in a given the minuteman namespace
76 77 78 |
# File 'lib/minuteman.rb', line 76 def operations @redis.keys([operations_cache_key_prefix, "*"].join("_")) end |
#reset_all ⇒ Object
Public: Resets all the used keys
89 90 91 92 |
# File 'lib/minuteman.rb', line 89 def reset_all keys = @redis.keys([PREFIX, "*"].join("_")) @redis.del(keys) if keys.any? end |
#reset_operations_cache ⇒ Object
Public: Resets the bit operation cache keys
82 83 84 85 |
# File 'lib/minuteman.rb', line 82 def reset_operations_cache keys = @redis.keys([operations_cache_key_prefix, "*"].join("_")) @redis.del(keys) if keys.any? end |