大多数情况下使用memcached获取此错误:
Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: /127.0.0.1:11211
对于此代码:
private byte[] cacheGet(String key) {
try {
if(mc == null) {
ConnectionFactory factory = new ConnectionFactoryBuilder()
.setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
.setFailureMode(FailureMode.Redistribute)
.setOpTimeout(MEMCACHED_TIMEOUT) // 60 seconds
.build();
ms = new MemcachedClient(factory, AddrUtil.getAddresses(Arrays.asList(MEMCACHED_CONN, MEMCACHED_CONN_2)));
}
Object value = mc.get(key);
return (byte[]) value;
} catch (Exception e) {
e.printStackTrace();
mc.shutdown();
mc = null;
} finally {
//mc.shutdown(); // needed?
}
return null;
}
我目前的解决方案是重新启动memcached服务器并解决问题,一切正常,缓存工作,但有一种方法可以优雅地处理这个问题,如果这只是一个客户端错误或下一次命中它将工作这是一个不可恢复的memcached服务器错误吗?