views:

190

answers:

2
  1. item is json serialized not binary so it is readable.
  2. I am getting problem while trying to get the item, with php the key is working fine but when i access the item using same key in java it fails
  3. I have only one server so server hashing should not be aproblem
  4. I have done a wireshark analysis and seems to be of no help except that: java and php clients are looking different keys.

What do i need to do to fix it? For now i have created a php wrapper and is working fine but is not long term solution for me, any help would be appreciated.

A: 

If wireshark shows that the clients are sending different keys, doesn't that tell you exactly what the problem is?

How can it be that you are accessing the item with the same key in Java as in PHP yet the wireshark traffic shows a different key is sent? How do you know you are sending the same key? Is there some sort of configuration for the Java client you are missing?

matt b
Yes and that is what i asked how to fix it.Anyways the solution DanSingerman proposed works but there is intermittent failures.Any ways thanks a lot for helping me out on this, this has solved a great headache for me, i will keep you mosted with more information on intermittent failures.
+2  A: 

The problem is the default hashing algorithm memcache uses for PHP differs from the one used for java.

You can set the algorithm PHP uses with the configuration option memcache.hash_function (see http://us2.php.net/manual/en/memcache.ini.php - the default is crc32)

You can set the algorithm java uses with the setHashingAlg method:

static {
                String[] serverlist = { "cache0.server.com:12345", "cache1.server.com:12345" };

                SockIOPool pool = SockIOPool.getInstance();
                pool.setServers(serverlist);
                pool.setHashingAlg( SockIOPool.NEW_COMPAT_HASH );
                pool.initialize();      
        }

will make it also use crc32.

(see http://www.whalin.com/memcached/javadocs/com/danga/MemCached/SockIOPool.html - it defaults to java's native String.hashCode() )

If they are set to the same algorithm, your problem should be solved

DanSingerman