Java and PHP share memcached problems and solutions in storing data
Java and PHP share memcached problems and solutions in storing data
Posted by Demon at 05:57 a.m. on 2010
PHP writes the data Java cannot read, Java writes the data php reads garbled;
If you write your own Java memcached client based on the Memcache extension protocol provided by PHP, there will be no problem, we are talking about using
Java's memcachedclient package;
php_extension:php_memcache.dll/memcache.sojava_jar:memcachedclient [com.danga.memcached.*]
Solution:
After viewing memcachedclient source code, found that is set when the flags are different, Java is based on the storage value type to order flags.
public static final int Marker_byte = 1;public static final int Marker_boolean = 8192;public static final int MARK Er_integer = 4;public static final int Marker_long = 16384;public static final int Marker_character = 16;publ IC static final int marker_string = 32;public static final int Marker_stringbuffer = 64;public static final int MA Rker_float = 128;public static final int Marker_short = 256;public static final int marker_double = 512;publi C Static final int marker_date = 1024;public static final int Marker_stringbuilder = 2048;public static final in T Marker_bytearr = 4096;
For convenience, the data conversion between the two uses JSON format;
Both PHP and Java require a string type when storing the value type.
and PHP in $mem->set (key,value,expire), the bold department to note that this is necessary.
Then the PHP writes the data, Java side can be able to read smoothly, when PHP writes Array,object, the Java reads after the json.decode to be OK.
1/F Maozilee 2011-10-12
My JSON pass no problem, Memcache will be automatically judged and serialized.