I’m working with redis and ruby and attempting to issue a blpop within a thread, so that I can wait for an incoming item on a list.
The problem is that the code within the block for blpop never seems to get called. Here’s the sample code that I’m running (ruby 1.9.3):
require 'rubygems'
require 'redis'
def start_thread
@thread = Thread.new do
r = Redis.new
r.blpop("test", 0) do |key, message|
process_message(key, message)
end
end
redis = Redis.new
redis.rpush "test", "hello world"
end
def process_message(key, message)
@message = "#{key} was sent #{message}"
end
start_thread
@thread.join
p @message
Any help is greatly appreciated!
1 Answer