MemcachedClient c = new MemcachedClient(
new InetSocketAddress("hostname", portNum));

// Store a value (async) for one hour
c.set("someKey", 3600, someObject);
// Retrieve a value.
Object myObject = c.get("someKey");

lock memcache with cas
The cas() operation internally adds the timestamp to the request it sends to the memcache service. The service then compares the timestamp received with a cas() operation to the timestamp currently associated with the key. If they match, it updates the value and the timestamp, and returns success. If they don’t match, it leaves the value and timestamp alone, and returns failure. (By the way, it does not send the new timestamp back with a successful response. The only way to retrieve the timestamp is to call gets().)
ref :

// obtain CAS token value using gets method
CASValue casValue = mcc.gets("tutorialspoint");

// display CAS token value
System.out.println("CAS token - " + casValue);

// try to update data using memcached cas method
CASResponse casresp = mcc.cas("tutorialspoint", casValue.getCas(), 900, "Largest Tutorials-Library");

while (!CASResponse.OK.equals(casresp))

// retry


ref :


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s