I am trying to use memcached with both a php (memcached) and C# (enyim) client.
I have a scenario where I want to CAS a value in php. To do this I am using the following code:
$memcached = new Memcached;
$memcached->addServer('localhost', 11211) or die ("Could not connect");
$memcached->setOption(Memcached::OPT_COMPRESSION, false); // the enyim client doesn't support compression
do {
$entries = $memcached->get($theKey, null, $cas);
if ($memcached->getResultCode() == Memcached::RES_NOTFOUND) {
$entry = somearray("foo");
$memcached->add($theKey, $entry);
} else {
$entries[] = "bar";
$memcached->cas($cas, $theKey, $entries);
}
}
while ($memcached->getResultCode() != Memcached::RES_SUCCESS AND $memcached->getResultCode() != Memcached::RES_END);
This works all well and fine to begin with.
But then, when the C# client CAS’s the same value it goes wrong.
Php gives a warning at:
$entries = $memcached->get($theKey, null, $cas);
namely that:
PHP Warning: Memcached::get(): could not uncompress value in ... at line ...
And as a result an infinite loop occurs.
Now I tried to get the key from the memcached server via telnet and the data was right there.
In php I am also able to SET to this key without a problem.
I noticed one thing: after the php client has SET something, the flag was 0.
Now after the C# client has CAS’d the value, the flag was 274.
Is there some flag collision on the php lib going on? Or is it something else?
If anyone can help me resolve this problem I’d be gratefull!
lordstyx
[EDIT]
Well then. Since this question isn’t getting an answer let me put it differently.
Is there a way to stop the C# client from setting flag 274?
So I eventually found an answer to my problem. It might not help all of you, because I switched from the Enyim to the BeIT memcached client (http://code.google.com/p/beitmemcached/)
Now to make the BeIT client compatible with the php client you have to change Serializer.cs
In the enum SerializedType I changed the number of “String” to 0 and ByteArray to 2, which gave this:
I believe I went with BeIT because I couldn’t find or figure out how the flags worked in the Enyim client. If you understand how it work though, I’m sure that you can change that client in a same manner