lib/em-synchrony/em-redis.rb in em-synchrony-0.3.0.beta.1 vs lib/em-synchrony/em-redis.rb in em-synchrony-1.0.0
- old
+ new
@@ -19,17 +19,17 @@
conn = self.aconnect(*args)
conn.callback { f.resume(conn) }
Fiber.yield
end
-
+
alias :old_call_command :call_command
-
+
+ SYNC = ['add', 'auth']
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'
+ # async commands are 'a' prefixed
+ if (argv.first[0] == 'a') && !SYNC.include?(argv.first.to_s)
argv[0] = argv[0].to_s.slice(1,argv[0].size)
old_call_command(argv, &blk)
else
# wrap response blocks into fiber callbacks
@@ -40,8 +40,31 @@
old_call_command(argv, &clb)
Fiber.yield
end
end
+
+ # adapted from em-redis' implementation to use
+ # the asynchronous version of mget
+ def amapped_mget(*keys)
+ self.amget(*keys) do |response|
+ result = {}
+ response.each do |value|
+ key = keys.shift
+ result.merge!(key => value) unless value.nil?
+ end
+ yield result if block_given?
+ end
+ end
+
+ def mapped_mget(*keys)
+ f = Fiber.current
+
+ self.amapped_mget(*keys) do |values|
+ f.resume(values)
+ end
+
+ Fiber.yield
+ end
end
end
-end
\ No newline at end of file
+end