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(host = 'localhost', port = 11211)

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

### Public Instance methods

del(key, expires = 0, &cb)

Alias for delete

delete(key, expires = 0, &cb)

Delete the value associated with a key

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

get(*keys) {|*keys.map{ |k| values[k]| ...}

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] }

get_hash(*keys) {|keys.inject({}){ |hash, k| hash.update k => values[keys.index(k)] }| ...}

Gets multiple values as a hash

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

set(key, val, exptime = 0, &cb)

Set the value for a given key

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

[Validate]