Class: KMDB::EventBatch
- Inherits:
-
Object
- Object
- KMDB::EventBatch
- Extended by:
- SharedMethods
- Includes:
- SharedMethods
- Defined in:
- lib/kmdb/models/event_batch.rb
Overview
Models a list of events, in chronological order, spanning entire seconds. Abstracts (compressed) storage in Redis. This effectively acts as a write cache.
Defined Under Namespace
Modules: SharedMethods
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
- #events ⇒ Object
- #id ⇒ Object
-
#initialize(data, id: nil) ⇒ EventBatch
constructor
provide either and Array (when creating a batch) or and encoded String (when loading).
- #save! ⇒ Object
Methods included from SharedMethods
Constructor Details
#initialize(data, id: nil) ⇒ EventBatch
provide either and Array (when creating a batch) or and encoded String (when loading)
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/kmdb/models/event_batch.rb', line 15 def initialize(data, id:nil) case data when Array @events = data when String @encoded = data @id = id else raise ArgumentError end end |
Class Method Details
.find(id) ⇒ Object
37 38 39 40 41 |
# File 'lib/kmdb/models/event_batch.rb', line 37 def self.find(id) encoded = redis.get(id) return if encoded.nil? new(encoded, id: id) end |
Instance Method Details
#delete ⇒ Object
33 34 35 |
# File 'lib/kmdb/models/event_batch.rb', line 33 def delete redis.del(id) end |
#events ⇒ Object
43 44 45 |
# File 'lib/kmdb/models/event_batch.rb', line 43 def events @events ||= Marshal.load(Zlib.inflate(@encoded)) end |
#id ⇒ Object
47 48 49 |
# File 'lib/kmdb/models/event_batch.rb', line 47 def id @id ||= GlobalUID.get('batches').to_s end |
#save! ⇒ Object
27 28 29 30 31 |
# File 'lib/kmdb/models/event_batch.rb', line 27 def save! _check_redis_space! redis.set(id, _encoded) self end |