简体   繁体   English

使用Java的Memcached中的PHP共享对象

[英]Php share object in Memcached with Java

In my recently project. 在我最近的项目中。 I should share some data object in memcached between Java application and Php application. 我应该在Java应用程序和Php应用程序之间的memcached中共享一些数据对象。 Use Protobuf to handle the serialize/deserialize process. 使用Protobuf处理序列化/反序列化过程。

But when I write Data object serialize by Protobuf into Memcached in Java application,then Php application use Memcached->get() to get the cached Data object,then use PB4PHP to deserialize Data object. 但是,当我在Java应用程序中将由Protobuf序列化的Data对象写入Memcached时,然后Php应用程序使用Memcached-> get()获取缓存的Data对象,然后使用PB4PHP反序列化Data对象。 The error happens,it's Memcached->get() deserialize error. 发生错误,是Memcached-> get()反序列化错误。 like this: 像这样:

Memcached->get() unable to deserialize data. Memcached-> get()无法反序列化数据。

I think Php memcached library's method Memcached->get() has a default serialize process. 我认为Php memcached库的方法Memcached-> get()具有默认的序列化过程。 So they can't deserialize the Protobuf byte stream. 因此他们不能反序列化Protobuf字节流。

Does anyone know how to make it works. 有谁知道如何使它工作。

The way objects are stored in php and java are different. 对象在php和java中的存储方式不同。 Try storing them using some common format like JSON or XML rather than simple serialization. 尝试使用JSON或XML等常见格式存储它们,而不是简单的序列化。 And while fetching, convert it to Java or PHP again. 并且在获取时,再次将其转换为Java或PHP。 I'll suggest using JSON. 我建议使用JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM