Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

multi methods for remcached

  • Loading branch information...
commit cbe82421091907e47ed5693061ed5c24bc384a4c 1 parent 24ec4a4
@igrigorik authored
Showing with 47 additions and 15 deletions.
  1. +30 −15 lib/em-synchrony/em-remcached.rb
  2. +17 −0 spec/remcached_spec.rb
View
45 lib/em-synchrony/em-remcached.rb
@@ -16,37 +16,52 @@ def connect(servers)
Fiber.yield
end
-
+
%w[add get set delete].each do |type|
class_eval %[
- def a#{type}(contents, &callback)
+ def a#{type}(contents, &callback)
df = EventMachine::DefaultDeferrable.new
df.callback &callback
-
+
cb = Proc.new { |res| df.succeed(res) }
operation Request::#{type.capitalize}, contents, &cb
-
- df
+
+ df
end
-
+
def #{type}(contents, &callback)
fiber = Fiber.current
-
+
df = a#{type}(contents, &Proc.new { |res| fiber.resume(res) })
df.callback &callback
-
+
Fiber.yield
end
]
end
-
- # def set(contents, &callback)
- # operation Request::Set, contents, &callback
- # end
- # def delete(contents, &callback)
- # operation Request::Delete, contents, &callback
- # end
+ %w[add get set delete].each do |type|
+ class_eval %[
+ def amulti_#{type}(contents, &callback)
+ df = EventMachine::DefaultDeferrable.new
+ df.callback &callback
+
+ cb = Proc.new { |res| df.succeed(res) }
+ multi_operation Request::#{type.capitalize}, contents, &cb
+
+ df
+ end
+
+ def multi_#{type}(contents, &callback)
+ fiber = Fiber.current
+
+ df = amulti_#{type}(contents, &Proc.new { |res| fiber.resume(res) })
+ df.callback &callback
+
+ Fiber.yield
+ end
+ ]
+ end
end
end
View
17 spec/remcached_spec.rb
@@ -30,5 +30,22 @@
}.resume
end
end
+
+ it "should fire multi memcached requests" do
+ pending "remcached borked? opened a ticket"
+
+ EventMachine.run do
+ Fiber.new {
+
+ Memcached.connect %w(localhost)
+
+ Memcached.multi_get([{:key => 'foo'},{:key => 'bar'}, {:key => 'test'}]) do |res|
+ p res
+ end
+
+ EventMachine.stop
+ }.resume
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.