I am storing Set of values into the memcached client with key as setOfKeys. I am putting the value in the memcached as follows
Set<String> keys=new HashSet<String>();
mMemcachedClient = new MemcachedClient(new BinaryConnectionFactory(),
AddrUtil.getAddresses("172.22.65.111:11211 172.22.65.11:11211"));
public void put(Object key, Object value) throws Result {
try {
synchronized (mMemcachedClient) {
this.keys.add(key.toString());
if(keys.size()==1){
mMemcachedClient.set(String.valueOf(hg.hash("setOfKeys")),
7200, keys);
}
else{
mMemcachedClient.replace(String.valueOf(hg.hash("setOfKeys")),
7200, keys);
}
mMemcachedClient.set(String.valueOf(hg.hash(key.toString())),
7200, value);
}
} catch (Excep`enter code here`tion ex) {`enter code here`
mLogger.error(ex.getMessage());
throw new Result("ERROR_PUT_MEMCACHED_INTO_CACHE");
}
}
But when i try to fetch setOfKeys from the cache as follows it give me the error
net.spy.memcached.OperationTimeoutException: Timeout waiting for value
The set and replace functions in MemcachedClient are asynchronous and return Futures. You must call .get() on the returned object in order to get it to block until the operation is completed.
mMemcachedClient.set(String.valueOf(hg.hash("setOfKeys")), 7200, keys).get();
You should also check the returned value of the statement above in order to make sure the operation was successful.