Java and PHP share memcached data Note related issues

Source: Internet
Author: User
Tags php memcached php write
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

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