Java (spymemcached) and PHP (memcached)
NickName:Fretre Ask DateTime:2012-07-12T04:11:37

Java (spymemcached) and PHP (memcached)

I'm trying to build a Java app that will set data in Memcached and have a PHP script to get the same data later in the process. So far, I haven't been able to find a way to get a 100% hit rate. To make sure nothing was wrong with the SETs, I manually confirmed the data was added to Memcached. Based on Consistent hashing in PHP and Java, I tried to use KETAMA (see code below) without any success.

Configurations:
- Spymemcached (2.8.1)
- PHP (5.3.10)
- PECL/memcached (2.0.1)
- libmemcached (1.0.4)

What would be the best strategy to share data between Java and PHP? Is there a configuration I'm not using correctly? Should I be using another library?

Thank you for your help!


MemcachedClient client = new MemcachedClient
(ConnectionFactory) new ConnectionFactoryBuilder ()
.setProtocol (Protocol.TEXT)
.setHashAlg (DefaultHashAlgorithm.KETAMA_HASH)
.setFailureMode (FailureMode.Redistribute)
.setLocatorType (Locator.CONSISTENT).build(),
AddrUtil.getAddresses("192.168.0.101:11211 192.168.0.102:11211"));

$memcached = new Memcached();
$memcached->addserver('192.168.0.101', 11211);
$memcached->addserver('192.168.0.102', 11211);
$memcached->setOption(Memcached::OPT_DISTRIBUTION ,Memcached::DISTRIBUTION_CONSISTENT);
$memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);

Copyright Notice:Content Author:「Fretre」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11440681/java-spymemcached-and-php-memcached

Answers
ragnor 2012-07-12T08:32:46

In spymemcached there's a reported issue with KETAMA hashing algorithm. It refers to version 2.5rc1 but it seems that this still occurs. \n\nTry another java memcached client: xmemcached.",


Fretre 2012-07-13T13:17:46

For those who are thinking about doing the same thing, there's a better strategy. Twitter provided twemproxy (nutcracker), a fast and light-weight proxy for memcached. Using that, I don't have to worry if Java and PHP are using the same hashing algo, the proxy takes care of that.",


More about “Java (spymemcached) and PHP (memcached)” related questions

Java (spymemcached) and PHP (memcached)

I'm trying to build a Java app that will set data in Memcached and have a PHP script to get the same data later in the process. So far, I haven't been able to find a way to get a 100% hit rate. To ...

Show Detail

Items set with spymemcached cannot be fetched with php memcached

I am using spymemcached. I set a couple of items. Then I run a php script, however then I cannot get all those items using php memcached. PHP-Memcached can only partially retrieve those items. I c...

Show Detail

SpyMemcached and Memcached: SpyMemcached.getInstance(memcache.job) is invalid! check memcached.property

[2011-08-29 10:05:09.132]ALERT: SpyMemcached.getInstance(memcache.job) is invalid! check memcached.property . [2011-08-29 10:05:54.590]ALERT: SpyMemcached.getInstance(memcache.job) is invalid! check

Show Detail

spymemcached (Java Memcached Client)

Is there a way to collect the memcached stats using this API (spymemcached)? I know there are tools like cacti to collect information on Memcached Server. But I would like to collect, say, memory ...

Show Detail

How to connection pool memcached in Java (spymemcached)

The API I'm using, spymemcached, basically gives MemcachedClient memc = new MemCachedClient(new InetSocketAddress("host", port)); It doesn't really give me a connect() or isConnected() function. ...

Show Detail

Memcached consistent hashing - spymemcached

I want to have memcached consistant hashing enabled. I've looked at phpinfo(); and I can see the following - last line "memcached.sess_consistent_hash": memcached memcached support enabled Vers...

Show Detail

How to cache a Memcached connection using the java spymemcached client

I am learning how to cache objects using memcached with the spymemcached client from spymemcached examples MemcachedClient c=new MemcachedClient(new InetSocketAddress("hostname", portNum)); //...

Show Detail

memcached (spymemcached) counters and expiry time

can anybody tell me (or point to some documentation that documents) how memcached counters work? Specifically: how do they expire? I'm using the java spymemcached client. The method net.spy.mem...

Show Detail

Spymemcached conflict with hibernate-memcached and webapp-runner

I've got a Heroku Java app that makes use of the Spymemcached library, which in my case is included by my use of the hibernate-memcached library (1.3). I now need to make sure that all requests to...

Show Detail

How to add memcached nodes dynamically with spymemcached

I have a Java application setup which has multiple memcached server nodes communicating with a spymemcached client. I want to know if it is possible to add or remove server nodes at runtime, without

Show Detail