Class: SlackBotServer::RedisQueue
- Inherits:
-
Object
- Object
- SlackBotServer::RedisQueue
- Defined in:
- lib/slack_bot_server/redis_queue.rb
Overview
An implementation of the quue interface that uses Redis as a data conduit.
Instance Method Summary collapse
-
#clear ⇒ nil
Clears the queue.
-
#initialize(redis: nil, key: 'slack_bot_server:queue') ⇒ RedisQueue
constructor
Creates a new queue.
-
#pop ⇒ Object
Pop a value from the front of the queue.
-
#push(value) ⇒ Object
Push a value onto the back of the queue.
Constructor Details
#initialize(redis: nil, key: 'slack_bot_server:queue') ⇒ RedisQueue
Creates a new queue
10 11 12 13 14 15 16 17 18 |
# File 'lib/slack_bot_server/redis_queue.rb', line 10 def initialize(redis: nil, key: 'slack_bot_server:queue') @key = key @redis = if redis redis else require 'redis' Redis.new end end |
Instance Method Details
#clear ⇒ nil
Clears the queue
40 41 42 |
# File 'lib/slack_bot_server/redis_queue.rb', line 40 def clear @redis.del @key end |
#pop ⇒ Object
Pop a value from the front of the queue
29 30 31 32 33 34 35 36 |
# File 'lib/slack_bot_server/redis_queue.rb', line 29 def pop json_value = @redis.lpop @key if json_value MultiJson.load(json_value, symbolize_keys: true) else nil end end |
#push(value) ⇒ Object
Push a value onto the back of the queue.
22 23 24 |
# File 'lib/slack_bot_server/redis_queue.rb', line 22 def push(value) @redis.rpush @key, MultiJson.dump(value) end |