Basic help required for the JAVA API

Arnaud Connois arnaud-memcached at
Mon Apr 9 14:36:16 UTC 2007

Hi all,

I've been using memcached for many year with great success with PHP.

I'm building now a new application based on the Java API of Memcached 
which is going to run in background of my website 
(Apache/PHP/Mysql/Memcached) to generate complex data structures out of 
existing structures already in the cache.

I've plugged into my mysql database quite easily, and I am now trying to 
plug into memcached. I'm kind of stuck at a very basic level to retreive 
data stored previously from PHP, probably beacuse of the fact that I'm 
not very used to Java, and more to PHP...

So here is the idea :

I have some arrays stored by php in the memcached and I'm trying to read 
them from the Java API...

Here is a sample code...

        String[] serverlist = { "localhost:11001" };
        SockIOPool memcached_pool = SockIOPool.getInstance();
        memcached_pool.setServers( serverlist );

        MemCachedClient mc = new MemCachedClient();

        Object myarray = mc.get( "list__2__smileys_to" );
        System.out.println( "Query Result : " + myarray );

I get a null result...

Query Result : null

I guess it cannot make sence of the serialized data...

To make sure my structiure was there and readable I tried with 
"asString" set to TRUE in the get method :

        String mystring = (String)mc.get( "list__2__smileys_to", null, 
true );
        System.out.println( "Query Result : " + mystring );

and I get a correct result :

com.danga.MemCached.MemCachedClient Mon Apr 09 15:57:11 CEST 2007 - ++++ 
retrieving object and stuffing into a string.
Query Result : 

 - How can I use this data store as a PHP array from the Java API and 
have the serialised array being store into a Java object ?
 - Which java object showld I use ?
 - What synthax shoud I use ?

I'm sure we have a few Java gurus on this list who are gonna fix that 
for me in a few minutes...

Many Thanks


More information about the memcached mailing list