Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

support for get, add, delete, set within remcached client

  • Loading branch information...
commit 24ec4a4d4762cf69b44357979f6d84114e92d665 1 parent 113a343
@igrigorik authored
Showing with 29 additions and 28 deletions.
  1. +16 −13 lib/em-synchrony/em-remcached.rb
  2. +13 −15 spec/remcached_spec.rb
View
29 lib/em-synchrony/em-remcached.rb
@@ -17,26 +17,29 @@ def connect(servers)
Fiber.yield
end
- def aget(contents, &callback)
- df = EventMachine::DefaultDeferrable.new
- df.callback &callback
+ %w[add get set delete].each do |type|
+ class_eval %[
+ def a#{type}(contents, &callback)
+ df = EventMachine::DefaultDeferrable.new
+ df.callback &callback
- cb = Proc.new { |res| df.succeed(res) }
- operation Request::Get, contents, &cb
+ cb = Proc.new { |res| df.succeed(res) }
+ operation Request::#{type.capitalize}, contents, &cb
- df
- end
+ df
+ end
- def get(contents, &callback)
- fiber = Fiber.current
+ def #{type}(contents, &callback)
+ fiber = Fiber.current
- df = aget(contents, &Proc.new { |res| fiber.resume(res) })
- df.callback &callback
+ df = a#{type}(contents, &Proc.new { |res| fiber.resume(res) })
+ df.callback &callback
- Fiber.yield
+ Fiber.yield
+ end
+ ]
end
-
# def set(contents, &callback)
# operation Request::Set, contents, &callback
# end
View
28 spec/remcached_spec.rb
@@ -4,30 +4,28 @@
describe Memcached do
it "should yield until connection is ready" do
- EventMachine.run do
- Fiber.new {
- Memcached.connect %w(localhost)
- Memcached.usable?.should be_true
- EventMachine.stop
- }.resume
- end
- end
+ EventMachine.run do
+ Fiber.new {
+ Memcached.connect %w(localhost)
+ Memcached.usable?.should be_true
+ EventMachine.stop
+ }.resume
+ end
+ end
it "should fire sequential memcached requests" do
EventMachine.run do
Fiber.new {
Memcached.connect %w(localhost)
-
- Memcached.get(:key => 'hai') do |res|
+ Memcached.get(key: 'hai') do |res|
res[:value].should match('Not found')
end
-
- # p Memcached.set({:key => 'hai', :value => 'win'})
- # p Memcached.set(:key => 'Hello', :value => 'Planet')
-
-
+ Memcached.set(key: 'hai', value: 'win')
+ Memcached.add(key: 'count')
+ Memcached.delete(key: 'hai')
+
EventMachine.stop
}.resume
end
Please sign in to comment.
Something went wrong with that request. Please try again.