net.spy.memcached.OperationTimeoutException:超时等待值

时间:2013-07-30 12:27:51

标签: java memcached spymemcached

我将值集存储到memcached客户端,其密钥为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: Timeout waiting for value

1 个答案:

答案 0 :(得分:2)

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

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

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