Export to GitHub

spymemcached - issue #314

Unable to read Binary data (C Struct) from Memcache


Posted on Dec 3, 2014 by Happy Giraffe

I am using 2.10.4 on Linux Operating System.

My Java project is reading C Structure from Memcache server. I am using Object net.spy.memcached.MemcachedClient.get(String key) function but not able to cast Object as byte[] array. This force me to use String then object serialization converting to byte array back but didn't find success.

Is there any way to get value in byte[] array so that I can easily manipulate ?

Kindly provide solution for this.

Comment #1

Posted on Dec 3, 2014 by Helpful Lion

I think the easiest for you would be to create a custom transcoder. Just check the default implementation, implement the skeleton as a "pass through" and provide it to the get command. This will return you the byte[] directly as we take it from NIO.

Comment #2

Posted on Dec 3, 2014 by Happy Giraffe

Comment deleted

Comment #3

Posted on Dec 3, 2014 by Happy Giraffe

Thanks for your quick revert. I created one custom Transcode and passed it through get command.

I am getting following error..

java.lang.IllegalArgumentException: Cannot cache data larger than 0 bytes (you tried to cache a 4 byte object) at net.spy.memcached.CachedData.(CachedData.java:55) at net.spy.memcached.MemcachedClient$5.gotData(MemcachedClient.java:1031) at net.spy.memcached.protocol.ascii.BaseGetOpImpl.handleRead(BaseGetOpImpl.java:147) at net.spy.memcached.protocol.ascii.OperationImpl.readFromBuffer(OperationImpl.java:129) at net.spy.memcached.MemcachedConnection.readBufferAndLogMetrics(MemcachedConnection.java:813) at net.spy.memcached.MemcachedConnection.handleReads(MemcachedConnection.java:792) at net.spy.memcached.MemcachedConnection.handleReadsAndWrites(MemcachedConnection.java:672) at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:635) at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:409

Could you please point to some examples for implementation.

Comment #4

Posted on Dec 3, 2014 by Helpful Lion

Just for the sake of decoding maybe try: https://gist.github.com/daschl/ef05c435c36ef1dfdb5c

Comment #5

Posted on Dec 3, 2014 by Helpful Lion

Comment deleted

Comment #6

Posted on Dec 4, 2014 by Happy Giraffe

Thanks Working fine.

Comment #7

Posted on Dec 4, 2014 by Helpful Lion

Cheers! If you want to write data just implement this one also as a passthrough

Status: New

Labels:
Type-Defect Priority-Medium