gpt4 book ai didi

java - net.spy.memcached.OperationTimeoutException : Timeout waiting for value

转载 作者:行者123 更新时间:2023-11-30 09:19:30 24 4
gpt4 key购买 nike

我将一组值存储到内存缓存客户端中,键为 setOfKeys。我将值放入 memcached 中,如下所示

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");
}
}

但是当我尝试从缓存中获取 setOfKeys 时,它给出了错误

net.spy.memcached.OperationTimeoutException:WAITING值超时

最佳答案

MemcachedClient 中的set 和replace 函数是异步的并且返回Futures。您必须对返回的对象调用 .get() 以使其阻塞,直到操作完成。

mMemcachedClient.set(String.valueOf(hg.hash("setOfKeys")), 7200, keys).get();

您还应该检查上述语句的返回值,以确保操作成功。

关于java - net.spy.memcached.OperationTimeoutException : Timeout waiting for value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17947047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com