Class: Rebot::RedisQueue
- Inherits:
-
Object
- Object
- Rebot::RedisQueue
- Defined in:
- lib/rebot/redis_queue.rb
Instance Method Summary collapse
-
#initialize(redis = nil) ⇒ RedisQueue
constructor
A new instance of RedisQueue.
- #pop ⇒ Object
- #push(value) ⇒ Object
Constructor Details
#initialize(redis = nil) ⇒ RedisQueue
Returns a new instance of RedisQueue.
3 4 5 6 7 8 9 10 11 |
# File 'lib/rebot/redis_queue.rb', line 3 def initialize(redis=nil) @key = 'rebot:queue' @redis = if redis redis else require 'redis' Redis.new end end |
Instance Method Details
#pop ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/rebot/redis_queue.rb', line 17 def pop json_value = @redis.lpop @key if json_value MultiJson.load(json_value, symbolize_keys: true) else nil end end |
#push(value) ⇒ Object
13 14 15 |
# File 'lib/rebot/redis_queue.rb', line 13 def push(value) @redis.rpush @key, JSON.dump(value) end |