0

我正在尝试并行执行多个 redis 查询,但出现错误:

/var/lib/gems/1.9.1/gems/em-synchrony-1.0.2/lib/em-synchrony.rb:53:in `resume':
dead fiber called (FiberError)

这是代码:

require 'em-synchrony'
require 'redis/connection/synchrony'
require 'redis'

redis = EM::Synchrony::ConnectionPool.new(size: 4) do
  Redis.new
end

EM.synchrony do
  multi = EM::Synchrony::Multi.new
  multi.add :a, redis.alpush('foo', 1)
  multi.add :b, redis.alpush('foo', 2)
  res = multi.perform

  p res

  EM.stop
end

请帮忙

4

1 回答 1

1

使用 Eventmachine 特定em-hiredisgem 而不是默认驱动程序。

gem install em-hiredis

require 'em-synchrony'
require 'em-synchrony/em-hiredis'

redis = EM::Synchrony::ConnectionPool.new(size: 4) do
          EM::Hiredis.new
        end

在任何地方EM::Synchrony都可以使用,通常建议使用随em-synchrony. 这就是为什么声明em-synchrony/em-hiredis而不是require em-synchrony.

于 2012-12-02T17:47:18.387 回答