INTRODUCTION
Evented Memcache Client is a memcache client written for Ruby’s EventMachine. It implements a full (though simple) memcache client.
INSTALLATION
You’ll need eventmachine:
sudo gem install eventmachine
Then:
sudo gem install evented-memcache-client
Naturally a running memcache or starling is needed too. I use starling:
sudo gem install starling
sudo starling -p 12345
USAGE
Here is a producer:
require 'rubygems'
require 'eventmachine'
require 'evented-memcache-client'
callbacks = {
:open => Proc.new { |conn|
conn.set(:key => 'x', :data => Time.now.to_s)
},
:stored => Proc.new { |conn, data, args|
puts "Stored a value"
EventMachine::stop
},
}
EventMachine::run {
EventMachine::connect('127.0.0.1',
12345,
EventMachine::Protocols::Memcache::Client,
callbacks)
}
And here is a consumer:
require 'rubygems'
require 'eventmachine'
require 'evented-memcache-client'
callbacks = {
:open => Proc.new { |conn|
puts 'Opened connection. Fetching...'
conn.get(:key => 'x')
},
:value => Proc.new { |conn, data, args|
key = args[0]
flags = args[1]
puts "Received message: '#{data}'"
puts 'Fetching more...'
conn.get(:key => 'x')
}
}
EventMachine::run {
EventMachine::connect('127.0.0.1',
12345,
EventMachine::Protocols::Memcache::Client,
callbacks)
}
TODO
Needs a test suite.