Search code examples
serializationmemcachednettyfinagle

Save object to memcached with Finagle memcached client


com / twitter / finagle / memcached / Client extends BaseClient[ChannelBuffer]

so the set is defined as

set(key: String, flags: Int, expiry: Time, value: ChannelBuffer): Future[Unit]

My question is how can I convert my java Object to a netty ChannelBuffer or I have some other way to set object other than String?

Thanks


Solution

  • Finally, I used thrift to do the serialization. It's just my case, because I have heavily used thrift.

    The disadvantage of thrift serialization: you had to define the struct of the object in the IDL.

    The advantage is: simple

    TSerializer serializer = new TSerializer();
    byte[] bytes = serializer.serialize(obj);
    ChannelBuffer buffer = ChannelBufferUtils.bytesToChannelBuffer(bytes);