Sha256: 887e367417b472cb431c4c07bc9c3c3abcd972258fbe87587c4d16927c97f157
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
begin require 'em-redis' rescue LoadError => error raise 'Missing EM-Synchrony dependency: gem install em-redis' end module EventMachine module Protocols module Redis attr_reader :connected class << self alias :aconnect :connect end def self.connect(*args) f = Fiber.current conn = self.aconnect(*args) conn.callback { f.resume(conn) } Fiber.yield end def call_command(argv, &blk) # async commands are 'a' prefixed, but do check # for the 'add' command corner case (ugh) if argv.first.size > 3 && argv.first[0] == 'a' argv[0] = argv[0].to_s.slice(1,argv[0].size) callback { raw_call_command(argv, &blk) } else # wrap response blocks into fiber callbacks # to emulate the sync api f = Fiber.current blk = proc { |v| v } if !block_given? clb = proc { |v| f.resume(blk.call(v)) } callback { raw_call_command(argv, &clb) } Fiber.yield end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
em-synchrony-0.2.0 | lib/em-synchrony/em-redis.rb |