Class: Rebot::RedisQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/rebot/redis_queue.rb

Instance Method Summary collapse

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

#popObject



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