Alternative java client

Dustin Sallings dustin at spy.net
Fri Mar 30 20:45:31 UTC 2007


	In case anyone's interested, I wrote a java 5 memcached client a  
while back that I've had a reasonable amount of success with.

	The goal was to have an asynchronous single-threaded client that was  
resilient to server faults.  I seem to have met that goal for myself  
and would like to share it with anyone else who's interested.

	The overview page (maven1) can be found here:

	http://bleu.west.spy.net/~dustin/projects/memcached/

	If you want to grab the source and play around, it's here:

	http://rubik.west.spy.net/hg/memcached/

	Latest binary release comes out of my maven 1 repo:

	http://bleu.west.spy.net/~dustin/repo/spy/jars/memcached-1.0.38.jar


	Example synchronous usage (from the javadocs):

   MemcachedClient c=new MemcachedClient(
       new InetSocketAddress("hostname", portNum));

   // Store a value (async) for one hour
   c.set("someKey", 3600, someObject);
   // Retrieve a value.
   Object myObject=c.get("someKey");


	Example asynchronous usage (assuming a server is slow or broken):

   // Try to get a value, for up to 5 seconds, and cancel if it  
doesn't return
   Object myObj=null;
   Future<Object> f=c.asyncGet("someKey");
   try {
       myObj=f.get(5, TimeUnit.SECONDS);
   } catch(TimeoutException e) {
       // Since we don't need this, go ahead and cancel the  
operation.  This
       // is not strictly necessary, but it'll save some work on the  
server.
       f.cancel();
       // Do other timeout related stuff
   }


-- 
Dustin Sallings


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20070330/19baa507/attachment.html


More information about the memcached mailing list