Java and php share Memcached data storage problems and solutions PostedbyDemonat05: 57 am on18, the data written by Aug2010php cannot be read by java, problems and Solutions in storing data using Memcached shared by java and php
Problems and Solutions in data storage using Memcached shared by Java and php
Posted by Demon at 05:57 AM on 18, Aug 2010
The data written by php cannot be read by java, and the data written by java is garbled by php;
If you write a java memcached client based on the memcache extension protocol provided by php, there will be no problem. here we mention using
Java MemCachedClient package;
php_extension: php_memcache.dll / memcache.sojava_jar: MemCachedClient [com.danga.MemCached.*]
Solution:
After checking the MemCachedClient source code, it is found that flags are different when set, and java sets flags based on the storage value type.
public static final int MARKER_BYTE = 1;public static final int MARKER_BOOLEAN = 8192;public static final int MARKER_INTEGER = 4;public static final int MARKER_LONG = 16384;public static final int MARKER_CHARACTER = 16;public static final int MARKER_STRING = 32;public static final int MARKER_STRINGBUFFER = 64;public static final int MARKER_FLOAT = 128;public static final int MARKER_SHORT = 256;public static final int MARKER_DOUBLE = 512;public static final int MARKER_DATE = 1024;public static final int MARKER_STRINGBUILDER = 2048;public static final int MARKER_BYTEARR = 4096;
For convenience, the data conversion between the two uses the JSON format;
Both php and java must be of the String type when they are stored,
And php in $ mem-> set (key, value,32, Expire); bold departments should note that this is required.
Then, the data written by php can be smoothly read by java. When php writes array and object, the json. decode after java reads the data is OK.
On the first floor, maozilee 2011-10-12 My data is transmitted in JSON format. MEMCACHE automatically judges and serializes the data.