Module EventMachine::Protocols::Memcache
In: lib/em/protocols/memcache.rb

Implements the Memcache protocol (code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt). Requires memcached >= 1.2.4 w/ noreply support

Usage example

  EM.run{
    cache = EM::P::Memcache.connect 'localhost', 11211

    cache.set :a, 'hello'
    cache.set :b, 'hi'
    cache.set :c, 'how are you?'
    cache.set :d, ''

    cache.get(:a){ |v| p v }
    cache.get_hash(:a, :b, :c, :d){ |v| p v }
    cache.get(:a,:b,:c,:d){ |a,b,c,d| p [a,b,c,d] }

    cache.get(:a,:z,:b,:y,:d){ |a,z,b,y,d| p [a,z,b,y,d] }

    cache.get(:missing){ |m| p [:missing=, m] }
    cache.set(:missing, 'abc'){ p :stored }
    cache.get(:missing){ |m| p [:missing=, m] }
    cache.del(:missing){ p :deleted }
    cache.get(:missing){ |m| p [:missing=, m] }
  }

Methods

connect   del   delete   get   get_hash   set  

Included Modules

EM::Deferrable

Public Class methods

Connect to a memcached server (must support NOREPLY, memcached >= 1.2.4)

Public Instance methods

del(key, expires = 0, &cb)

Alias for delete

Delete the value associated with a key

 cache.del :a
 cache.del(:b){ puts "deleted the value!" }

Get the value associated with one or multiple keys

 cache.get(:a){ |v| p v }
 cache.get(:a,:b,:c,:d){ |a,b,c,d| p [a,b,c,d] }

Gets multiple values as a hash

 cache.get_hash(:a, :b, :c, :d){ |h| puts h[:a] }

Set the value for a given key

 cache.set :a, 'hello'
 cache.set(:missing, 'abc'){ puts "stored the value!" }

[Validate]