Java and PHP share memcached storage Data related problems and solutions

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

  • 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.