Class: AppleShove::NotificationQueue
- Inherits:
-
Object
- Object
- AppleShove::NotificationQueue
- Defined in:
- lib/apple_shove/notification_queue.rb
Instance Method Summary collapse
- #add(notification) ⇒ Object
- #get ⇒ Object
-
#initialize(key, redis = Redis.new) ⇒ NotificationQueue
constructor
A new instance of NotificationQueue.
- #size ⇒ Object
Constructor Details
#initialize(key, redis = Redis.new) ⇒ NotificationQueue
Returns a new instance of NotificationQueue.
7 8 9 10 |
# File 'lib/apple_shove/notification_queue.rb', line 7 def initialize(key, redis = Redis.new) @redis = redis @key = key end |
Instance Method Details
#add(notification) ⇒ Object
12 13 14 |
# File 'lib/apple_shove/notification_queue.rb', line 12 def add(notification) @redis.rpush @key, notification.to_json end |
#get ⇒ Object
16 17 18 19 |
# File 'lib/apple_shove/notification_queue.rb', line 16 def get element = @redis.lpop @key element ? Notification.parse(element) : nil end |
#size ⇒ Object
21 22 23 |
# File 'lib/apple_shove/notification_queue.rb', line 21 def size @redis.llen @key end |