Class: Flamingo::DispatchQueue
- Inherits:
-
Object
- Object
- Flamingo::DispatchQueue
- Defined in:
- lib/flamingo/dispatch_queue.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
- #dequeue ⇒ Object
- #enqueue(event) ⇒ Object
-
#initialize(redis) ⇒ DispatchQueue
constructor
A new instance of DispatchQueue.
- #page(page_num, page_size = 20) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(redis) ⇒ DispatchQueue
Returns a new instance of DispatchQueue.
6 7 8 9 |
# File 'lib/flamingo/dispatch_queue.rb', line 6 def initialize(redis) self.redis = redis @queue_name = "queue:dispatch" end |
Instance Attribute Details
#redis ⇒ Object
Returns the value of attribute redis.
4 5 6 |
# File 'lib/flamingo/dispatch_queue.rb', line 4 def redis @redis end |
Instance Method Details
#dequeue ⇒ Object
15 16 17 |
# File 'lib/flamingo/dispatch_queue.rb', line 15 def dequeue redis.lpop(@queue_name) end |
#enqueue(event) ⇒ Object
11 12 13 |
# File 'lib/flamingo/dispatch_queue.rb', line 11 def enqueue(event) redis.rpush(@queue_name,event) end |
#page(page_num, page_size = 20) ⇒ Object
19 20 21 22 23 |
# File 'lib/flamingo/dispatch_queue.rb', line 19 def page(page_num,page_size=20) start_index = page_num*page_size end_index = start_index+page_size-1 redis.lrange(@queue_name,start_index,end_index) end |
#size ⇒ Object
25 26 27 |
# File 'lib/flamingo/dispatch_queue.rb', line 25 def size redis.llen(@queue_name) end |