Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do memcache clients of different languages hash the same way?

We would like to some processing in a Java application, store the results in our pool of memcache servers, and read it back using memcache in PHP.

This is easy enough to try, but I though I would ask and see if anyone else has done this.

As long as both the Java and PHP clients connect to the same pool of memcache servers, will both clients hash to the same server location making retrieval from PHP possible?

like image 778
Peter Sankauskas Avatar asked May 21 '09 22:05

Peter Sankauskas


2 Answers

No. Not all clients hash the same way. As evidence of this, you'll see that some clients offer "consistent hashing", while others don't.

In short, memcached clients are allowed to use any hashing algo they please. There is no official standard.

The PHP client supports a variety of hashing algorithms -- so it may be possible to configure it to use the same algo your Java library uses (it looks like there are several out there -- which are you using?). But you'll want to test heavily, obviously.

like image 141
Frank Farmer Avatar answered Sep 28 '22 05:09

Frank Farmer


Another possibility to allow cross-language access would be to not rely on the language serialization but store objects in JSON format, as String of text.

Personally, I use Gson for Java and the json_encode, json_decode in PHP.

like image 26
stivlo Avatar answered Sep 28 '22 05:09

stivlo