Java与php共享Memcached存储数据中的有关问题与解决办法

WBOY
Release: 2016-06-13 11:00:18
Original
757 people have browsed it

Java与php共享Memcached存储数据中的问题与解决方法

Java与php共享Memcached存储数据中的问题与解决方法

Posted by Demon at 05:57 上午 on 18, Aug 2010

php写入的数据java读不出来,java写入的数据php读取乱码;
如果你根据php提供的memcache扩展协议来自行编写java memcached client将不会有问题,我们这里提到的是使用
java的 MemCachedClient 包;

php_extension: php_memcache.dll / memcache.sojava_jar: MemCachedClient [com.danga.MemCached.*]
Copy after login

解决方案:
经过查看MemCachedClient源码,发现是 set 时 flags不同,java是根据存储值类型来订flags的。

	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;
Copy after login

为了方便,两者间的数据转换使用JSON格式;
php与java在存储的时候值类型均要求为String类型,
并且php在$mem->set(key,value,32,expire);加粗部门要注意,这个是必须的。
然后php写入的数据,java那边就能够顺利读取了,当php写入array,object时,java读取后json.decode就OK了。

1 楼 maozilee 2011-10-12  
我的用JSON传递没有问题,MEMCACHE会自动判断和序列化。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!