Module: EventMachine::Protocols::Redis

Defined in:
lib/em-synchrony/em-redis.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectedObject (readonly)

Returns the value of attribute connected.



10
11
12
# File 'lib/em-synchrony/em-redis.rb', line 10

def connected
  @connected
end

Class Method Details

.aconnectObject



13
# File 'lib/em-synchrony/em-redis.rb', line 13

alias :aconnect :connect

.connect(*args) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/em-synchrony/em-redis.rb', line 16

def self.connect(*args)
  f = Fiber.current

  conn = self.aconnect(*args)
  conn.callback { f.resume(conn) }

  Fiber.yield
end

Instance Method Details

#call_command(argv, &blk) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/em-synchrony/em-redis.rb', line 25

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