我试图并行执行几个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
请帮助
答案 0 :(得分:1)
使用Eventmachine特定的em-hiredis
gem而不是默认驱动程序。
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
。