Created
July 9, 2014 02:20
-
-
Save paultyng/26fe49cfe425fbc1be14 to your computer and use it in GitHub Desktop.
RedisQueue mock for SQS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redis' | |
RedisMessage = Struct.new(:body) | |
class RedisQueue | |
def initialize(redis) | |
@redis = redis | |
end | |
def poll(&block) | |
loop do | |
queue, message = @redis.brpop("smartchat-queue") | |
# queue could be nil if a timeout happened | |
if queue | |
block.call(RedisMessage.new(message)) | |
end | |
end | |
end | |
def send_message(message_json) | |
@redis.lpush("smartchat-queue", message_json) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment