Problems related to data storage using Memcached shared by Java and php and solutions

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.