我正在使用合适的 Redis EM gem(在我的例子中为“em-hiredis”)读取 EventMachine 反应器循环中的 Redis 集,并且必须检查某些 Redis 集是否包含级联中的成员。我的目标是获取不为空的集合名称:
require 'eventmachine'
require 'em-hiredis'
def fetch_queue
  @redis.scard('todo').callback do |scard_todo|
    if scard_todo.zero?
      @redis.scard('failed_1').callback do |scard_failed_1|
        if scard_failed_1.zero?
          @redis.scard('failed_2').callback do |scard_failed_2|
            if scard_failed_2.zero?
              @redis.scard('failed_3').callback do |scard_failed_3|
                if scard_failed_3.zero?
                  EM.stop
                else
                  queue = 'failed_3'
                end 
              end 
            else
              queue = 'failed_2'
            end 
          end 
        else
          queue = 'failed_1'
        end 
      end 
    else
      queue = 'todo'
    end 
  end 
end
EM.run do
  @redis = EM::Hiredis.connect "redis://#{HOST}:#{PORT}"
  # How to get the value of fetch_queue?
  foo = fetch_queue
  puts foo
end
我的问题是:我如何告诉 EM 在 'fetch_queue' 中返回 'queue' 的值以在反应器循环中使用它?fetch_queue 中的简单“返回队列 = 'todo'”、“返回队列 = 'failed_1'”等会导致“意外返回 (LocalJumpError)”错误消息。