Java and PHP share memcached data attention issues
In many cases, the data in a memcached server needs to be accessed by clients in different languages.
In the ideal case, one language is written, and other language reads may not cause some compatibility problems.
Recently encountered the Java and PHP shared data problems, PHP write, Java can read, Java write, PHP read when the data parsing error.
Analyze the data in the memcached:
Telnet MEMCACHE-SRV1 11211
Get Key[enter]
There is a little difference between the discovery of PHP writes and the data written by Java.
Php:value Key 1 250
Java:value Key 0 250
Everyone found out, it is a state bit inconsistency caused. In Java, this state is used for other identifiers such as compression, whereas in PHP it is used as an object to judge PHP (e.g., array, etc.).
Check the PHP code, found that it is directly to the array object, to the PHP memcached function, by its serialization, and to join the identity, when reading, it directly feedback the corresponding PHP object.
Set: $out = Array (); $out [' field1 '] = "Me"; $MC->set ($key, $out, NULL, 3600); Get: $out = $MC->get ($key); echo $out [' field1 '];
Solution:
When using the memcached client to PHP, first serialize it well. When it is taken, it is deserialized once.
Set: $out = Array (); $out [' field1 '] = "Me"; $MC->set ($key, serilized ($out), NULL, 3600); Get: $out = $MC->get ($key); echo unserilized ($out) [' field1 '];
Or, modify the Java memcacheclient Source code, not recommended.
1/F a254939392 2011-10-11
A little bit drops of a little bit