Ahh right, I missed that part about one server. Yeah, likely a serialization issue.<br><br>gw<br><br><div><span class="gmail_quote">On 4/9/07, <b class="gmail_sendername">Steven Grimm</b> <<a href="mailto:sgrimm@facebook.com">
sgrimm@facebook.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
If he only has one server, how can it be the hashing? All the keys will
resolve to that one server no matter what the hash algorithm is.<br>
<br>
I think it's the serialization. Java's deserializer has no idea what to
make of PHP's serialization format.<br>
<br>
As I see it you have two options, if that's indeed the problem: you can
write your own serializer in PHP to serialize to some other format
(probably not Java's native format since that would be a real pain to
get right in PHP) or you can parse the PHP format in Java. PHP's
serialization format is pretty simple so that'd be the route I'd take.
You may be able to make some use of the PHP-in-Java implementation,
Quercus:<br>
<br>
<a href="http://quercus.caucho.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://quercus.caucho.com/</a><br>
<br>
It has code to deal with PHP-serialized objects, but I'm not sure what
it ends up building on the Java side.<br>
<br>
-Steve<div><span class="e" id="q_111d74e38c838c1e_1"><br>
<br>
<br>
Greg Whalin wrote:
<blockquote cite="http://middff213f90704090750x51df4f10sed4a1113ef70dd87@mail.gmail.com" type="cite">I doubt this is due to to serialization issues, though it
could be. By default, the Java client hashes using the default String
hashing as it is fast and pretty good for even key distribution. The
other clients have all agreed on a common hashing algorithm. The java
client supports this as well, but you need to configure it to use it.
So, you should:
<br>
<br>
String[] serverlist = { "localhost:11001" };<br>
SockIOPool memcached_pool = SockIOPool.getInstance();<br>
memcached_pool.setServers( serverlist );<br>
memcached_pool.<span>setHashingAlg( SockIOPool.NEW_COMPAT_HASH );<br>
</span>memcached_pool.initialize();<br>
<br>
MemCachedClient mc = new MemCachedClient();<br>
mc.<span>setPrimitiveAsString(true);<br>
</span><br>
This sets the hashing alg to the compat one (which I assume is used by
the PHP client), as well as stores all primitives as strings, which I
think the PHP client does as well.
<br>
<br>
gw<br>
<br>
<div><span class="gmail_quote">On 4/9/07, <b class="gmail_sendername">Arnaud
Connois</b> <<a href="mailto:arnaud-memcached@connois.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">arnaud-memcached@connois.com</a>>
wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Hi all,<br>
<br>
I've been using memcached for many year with great success with PHP.<br>
<br>
I'm building now a new application based on the Java API of Memcached<br>
which is going to run in background of my website
<br>
(Apache/PHP/Mysql/Memcached) to generate complex data structures out of<br>
existing structures already in the cache.<br>
<br>
I've plugged into my mysql database quite easily, and I am now trying to<br>
plug into memcached. I'm kind of stuck at a very basic level to
retreive
<br>
data stored previously from PHP, probably beacuse of the fact that I'm<br>
not very used to Java, and more to PHP...<br>
<br>
So here is the idea :<br>
<br>
I have some arrays stored by php in the memcached and I'm trying to
read
<br>
them from the Java API...<br>
<br>
Here is a sample code...<br>
<br>
String[] serverlist = { "localhost:11001" };<br>
SockIOPool memcached_pool = SockIOPool.getInstance();<br>
memcached_pool.setServers( serverlist );
<br>
memcached_pool.initialize();<br>
<br>
MemCachedClient mc = new MemCachedClient();<br>
<br>
Object myarray = mc.get( "list__2__smileys_to" );<br>
System.out.println( "Query Result : " + myarray );
<br>
<br>
I get a null result...<br>
<br>
Query Result : null<br>
<br>
I guess it cannot make sence of the serialized data...<br>
<br>
To make sure my structiure was there and readable I tried with<br>
"asString" set to TRUE in the get method :
<br>
<br>
String mystring = (String)mc.get( "list__2__smileys_to", null,<br>
true );<br>
System.out.println( "Query Result : " + mystring );<br>
<br>
and I get a correct result :<br>
<br>
com.danga.MemCached.MemCachedClient Mon Apr 09 15:57:11 CEST 2007 - ++++<br>
retrieving object and stuffing into a string.<br>
Query Result :<br>
a:15:{i:11;s:1:"3";i:3;s:1:"4";i:7;s:1:"3";i:9;s:1:"4";i:10;s:1:"3";i:21;s:1:"1";i:24;s:1:"4";i:25;s:1:"4";i:30;s:1:"3";i:19;s:1:"1";i:18;s:1:"0";i:17;s:1:"6";i:16;s:1:"1";i:14;s:1:"4";i:1;s:1:"3";}
<br>
<br>
- How can I use this data store as a PHP array from the Java API and<br>
have the serialised array being store into a Java object ?<br>
- Which java object showld I use ?<br>
- What synthax shoud I use ?<br>
<br>
I'm sure we have a few Java gurus on this list who are gonna fix that
<br>
for me in a few minutes...<br>
<br>
Many Thanks<br>
<br>
Arnaud<br>
<br>
<br>
<br>
<br>
<br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
Greg Whalin
</blockquote>
<br>
</span></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>Greg Whalin