Class: Railscope::Storage::RedisBuffer
- Defined in:
- lib/railscope/storage/redis_buffer.rb
Constant Summary collapse
- BUFFER_KEY =
"railscope:buffer"- UPDATES_KEY =
"railscope:buffer:updates"- BUFFER_TTL =
4.hours.to_i
Instance Method Summary collapse
- #all(filters: {}, page: 1, per_page: 25, displayable_only: true) ⇒ Object
- #count(filters: {}, displayable_only: true) ⇒ Object
- #destroy_all! ⇒ Object
- #destroy_expired! ⇒ Object
- #family_count(family_hash) ⇒ Object
-
#find(uuid) ⇒ Object
READ → Database (source of truth).
- #for_batch(batch_id) ⇒ Object
- #for_family(family_hash, page: 1, per_page: 25) ⇒ Object
-
#ready? ⇒ Boolean
READY → needs both Redis AND database.
-
#update_by_batch(batch_id:, entry_type:, payload_updates:) ⇒ Object
UPDATE → Redis buffer (for response data from middleware).
-
#write(attributes) ⇒ Object
WRITE → Redis (fast, ~0.1ms).
Methods inherited from Base
Instance Method Details
#all(filters: {}, page: 1, per_page: 25, displayable_only: true) ⇒ Object
34 35 36 |
# File 'lib/railscope/storage/redis_buffer.rb', line 34 def all(filters: {}, page: 1, per_page: 25, displayable_only: true) database_adapter.all(filters: filters, page: page, per_page: per_page, displayable_only: displayable_only) end |
#count(filters: {}, displayable_only: true) ⇒ Object
38 39 40 |
# File 'lib/railscope/storage/redis_buffer.rb', line 38 def count(filters: {}, displayable_only: true) database_adapter.count(filters: filters, displayable_only: displayable_only) end |
#destroy_all! ⇒ Object
54 55 56 57 |
# File 'lib/railscope/storage/redis_buffer.rb', line 54 def destroy_all! redis.del(BUFFER_KEY, UPDATES_KEY) database_adapter.destroy_all! end |
#destroy_expired! ⇒ Object
59 60 61 |
# File 'lib/railscope/storage/redis_buffer.rb', line 59 def destroy_expired! database_adapter.destroy_expired! end |
#family_count(family_hash) ⇒ Object
50 51 52 |
# File 'lib/railscope/storage/redis_buffer.rb', line 50 def family_count(family_hash) database_adapter.family_count(family_hash) end |
#find(uuid) ⇒ Object
READ → Database (source of truth)
30 31 32 |
# File 'lib/railscope/storage/redis_buffer.rb', line 30 def find(uuid) database_adapter.find(uuid) end |
#for_batch(batch_id) ⇒ Object
42 43 44 |
# File 'lib/railscope/storage/redis_buffer.rb', line 42 def for_batch(batch_id) database_adapter.for_batch(batch_id) end |
#for_family(family_hash, page: 1, per_page: 25) ⇒ Object
46 47 48 |
# File 'lib/railscope/storage/redis_buffer.rb', line 46 def for_family(family_hash, page: 1, per_page: 25) database_adapter.for_family(family_hash, page: page, per_page: per_page) end |
#ready? ⇒ Boolean
READY → needs both Redis AND database
64 65 66 |
# File 'lib/railscope/storage/redis_buffer.rb', line 64 def ready? Railscope.redis_available? && database_adapter.ready? end |
#update_by_batch(batch_id:, entry_type:, payload_updates:) ⇒ Object
UPDATE → Redis buffer (for response data from middleware)
19 20 21 22 23 24 25 26 27 |
# File 'lib/railscope/storage/redis_buffer.rb', line 19 def update_by_batch(batch_id:, entry_type:, payload_updates:) update = { batch_id: batch_id, entry_type: entry_type, payload_updates: payload_updates } redis.rpush(UPDATES_KEY, update.to_json) redis.expire(UPDATES_KEY, BUFFER_TTL) end |
#write(attributes) ⇒ Object
WRITE → Redis (fast, ~0.1ms)
11 12 13 14 15 16 |
# File 'lib/railscope/storage/redis_buffer.rb', line 11 def write(attributes) entry = build_entry(attributes) redis.rpush(BUFFER_KEY, entry.to_json) redis.expire(BUFFER_KEY, BUFFER_TTL) entry end |