class SlackBotServer::RedisQueue
An implementation of the quue interface that uses Redis as a data conduit.
Public Class Methods
new(redis: nil, key: 'slack_bot_server:queue')
click to toggle source
Creates a new queue @param redis [Redis] an instance of the ruby Redis
client. If
nil, one will be created using the default hostname and port
@param key [String] the key to store the queue against
# 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
Public Instance Methods
clear()
click to toggle source
Clears the queue @return [nil]
# File lib/slack_bot_server/redis_queue.rb, line 40 def clear @redis.del @key end
pop()
click to toggle source
Pop a value from the front of the queue @return [Object] the object on the queue, reconstituted from its
JSON string
# 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)
click to toggle source
Push a value onto the back of the queue. @param value [Object] this will be turned into JSON when stored
# File lib/slack_bot_server/redis_queue.rb, line 22 def push(value) @redis.rpush @key, MultiJson.dump(value) end