Module | EventMachine::Protocols::Memcache
In: | lib/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 connection_completed del delete get get_hash new process_cmd receive_data set unbind

### Included Modules

EM::Deferrable

### Classes and Modules

Class EventMachine::Protocols::Memcache::ParserError

### Constants

Cstored | = | 'STORED'.freeze
Cend | = | 'END'.freeze
Cdeleted | = | 'DELETED'.freeze
Cunknown | = | 'NOT_FOUND'.freeze
Cerror | = | 'ERROR'.freeze
Cempty | = | ''.freeze
Cdelimiter | = | "\r\n".freeze

### Public Class methods

connect(host = 'localhost', port = 11211)

em hooks

new(host, port = 11211)

### Public Instance methods

connection_completed()
del(key, expires = 0, &cb)

Alias for delete

delete(key, expires = 0, &cb)
get(*keys) {|*keys.map{ |k| values[k]| ...}

commands

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

def receive_line line

receive_data(data)

19Feb09 Switched to a custom parser, LineText2 is recursive and can cause

            stack overflows when there is too much data.

include EM::P::LineText2

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

def receive_binary_data data

      @values[@cur_key] = data[0..-3]

end

[Validate]