how to use EM::Synchrony::Multi with redis?

745 views Asked by At

I am trying to perform several redis queries in parallel, but getting an error:

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

here is the code:

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

please help

1

There are 1 answers

0
Kashyap On BEST ANSWER

Use the Eventmachine specific em-hiredis gem instead of the default driver.

gem install em-hiredis

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

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

Anywhere EM::Synchrony is used, it is usually suggested to use the synchrony specific library shipped with em-synchrony. That is why the statement em-synchrony/em-hiredis and not require em-synchrony.