Do memcache clients of different languages โ€‹โ€‹have a hash the same way?

We would like to process it in a Java application, save the results in our memcache server pool and read it using memcache in PHP.

It's easy enough to try, but I would ask and see if anyone else has done this.

As long as both Java and PHP clients connect to the same memcache server pool, will the hash address of both clients be the same server to make searching with PHP possible?

+7
java php memcached
source share
3 answers

Not. Not all clients hash too. As evidence of this, you will see that some clients offer "consecutive hashing," while others do not.

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

The PHP client supports many hashing algorithms - so it may be possible to configure it to use the same algorithm of your Java library (there seems to be a few that you use?). But you will want to check, obviously, that.

+4
source share

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

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

+1
source share

pylibmc

import pylibmc mc = pylibmc.Client(["127.0.0.1"], binary=True, behaviors={"tcp_nodelay": True, "ketama": True}) key="someKey" i=0 while True: #mc.set(key, str(i)) value = mc.get(key) print(value) sleep(1) i+=1 
0
source share

All Articles