How to save an object into memcache

67 views
Skip to first unread message

Pratik Patel

unread,
Mar 29, 2013, 8:34:07 AM3/29/13
to spymem...@googlegroups.com

Hi,

I am new to memcache and trying to save an object in the memcache server.

Unfortunately, the object is not saved properly and while trying to retrieve, I am getting only null value.

I tried to write the Transcoder but no luck.

Here is the code snippet.

          MemcachedClient memClient = new MemcachedClient(new BinaryConnectionFactory(),AddrUtil.getAddresses("192.168.6.214:11211"));         
          Transcoder<Employee> transcoder = new EmployeeTranscoder();
          Employee e=new Employee(1,"Test User",1500);
          System.out.println("Putting the employee into memcache");
          memClient.set(keyName, 36000, e, transcoder);
          Employee obj = memClient.get(keyName,transcoder);
          System.out.println("Fetching the object from memcache: "+obj);

Attached is the EmployeeTranscoder.java file.

The value string in the DB is, ACED0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Only first four bytes are populated, rest are null. I have attached screenshot of wireshark capture for set operation.

Can someone please advise how to fix the problem?


Many Thanks,
Pratik

EmployeeTranscoder.java
screenshot-set-operation.jpg

Matt Ingenthron

unread,
Mar 29, 2013, 9:56:19 PM3/29/13
to spymem...@googlegroups.com
Hi Pratik,

I didn't look that closely at your source code, but there are a few sections there that indicate encode/decode failures may be going to stderr or something like that.

What I'd recommend if you're writing a transcoder is to build a unit test around it.  Having something like that will make it easier to isolate where the problem is by running it under a debugger, etc.

Hope that helps,

Matt




--
You received this message because you are subscribed to the Google Groups "spymemcached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spymemcached...@googlegroups.com.
To post to this group, send email to spymem...@googlegroups.com.
Visit this group at http://groups.google.com/group/spymemcached?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
Message has been deleted
0 new messages