memcache API happiness for C and Ruby users...

Sean Chittenden sean at chittenden.org
Wed Jan 5 00:01:49 PST 2005


Happy holidays 'all.  Few things to note.

memcache(3):

Nearing the 1.2.0 release for memcache(3).  Had lots of feedback so far 
and I'm quite happy with it at the moment.  There are a few API 
changes, but they're super trivial (sed(1) could fix any problems that 
pop up if you have any, most people shouldn't be bit).  You've been 
warned, however.  This is an ABI incompatible release, however.  A bit 
has changed.  ChangeLog can be found:

http://people.FreeBSD.org/~seanc/libmemcache/libmemcache-1.2.0/ChangeLog

The only bit that I have outstanding is with multi-get requests in that 
I need to do add a scatter-gather algo to have the get's for the 
various keys distributed across the appropriate servers then have the 
various keys reassembled and returned in the correct order.  I'll 
likely tackle that in a 1.3.0 release, however and not in the 1.2.0 
cycle.  Please test and let me know if anyone has any probs w/ this 
version of memcache(3).


ruby-memcache(3):

Courtesy of the King County Superior Court and its jury selection 
process, I'm pleased to announce the availability of ruby-memcache:

http://rubyforge.org/frs/download.php/2484/ruby-memcache-0.1.0.tar.bz2

It's quite functional, though missing an API doc.  The nuts and bolts, 
however are:

> require 'memcache'
>
> m = Memcache.new()
>
> m.add_server('127.0.0.1') # someone should register port 11211 as a 
> memcache protocol with IANA
> m.add_server('127.0.0.1:11212')
> m.add_server('127.0.0.1','11213')
> m.add('foo')
> m.add('foobar', 'baz')
> m.set('foobar', 'baz')
> m.replace('foobar','blah')
> m.set('counter', '0')
> m.incr('counter')
> p m.get('foobar')
> m['foobar'] = 'boo'
> p m['foobar']
> p m['key1'] = 'val1'
> p m['key2'] = 'val2'
> p m['key4'] = 'val4'
> p m.get_a('key1', 'key2', 'key3', 'key4')
> p m.get_h('key1', 'key2', 'key3', 'key4')
>
> 1.upto(1000) do |x|
>   m.get('foobar')
> end

The #get_a() and #get_h() methods are of interest as they're the 
multi-get methods.  The outputs of the gets are:

m['key1']									>>	"val1"
m.get('key1')								>>	"val1"
m.get_a('key1', 'key2', 'key3', 'key4')		>>	["val1", "val2", nil, 
"val4"]
m.get_h('key1', 'key2', 'key3', 'key4')		>>	{"key1"=>"val1", 
"key2"=>"val2", "key3"=>nil, "key4"=>"val4"}

Please note that the: [] and []= methods are the same as #get and #set, 
respectively.  Let me know if anyone has any Q's or bugs, there may be 
a few lurking, though I haven't found any with the ruby bindings.  I 
think it'd be great if someone (me?) would come up with a list of 
client flags and what their respective data types were.  A common 
binary data format would be nifty for language independent memcache 
access, but is more of a project than I have any hope of completing in 
the next few years.  Anyone know of a good open source (BSD license or 
MIT only, GPL--) library that does this that *is not* XML based?  Oh, 
this library supports marshaling of data too, so custom data types 
(hashes, arrays, etc.) are supported.

-sc

-- 
Sean Chittenden



More information about the memcached mailing list