spymemcached和spring整合,使用过程出现Timeout waiting for value异常

时间:2022-09-09 08:04:38

环境:

spymemcached-2.8.4

windows 7

myeclipse 10

memcached-win32-1.4.4-14


背景:

在终端登录成功后会调用spymemcached的set方法,把用户对象放入Memcached(key是用户Id),之后在获取其他模块信息前,先判断提交到后台的用户id是否存在于Memcached,如果不存在则说明是违法进入,提示重新登录。


问题:

在测试的时候,经常出现Timeout waiting for value异常,谷歌了一下,有一帖子说是Bug,但之后更换了spymemcached-2.9.0,还是会出现这个问题。重新看了一下spring的配置文件,发现OpTimeout设置为2,搜索了一下,终于发现了问题的根源,原来OpTimeout设置“操作超时时间”,单位是“毫秒”,这下明白了,是因为超时时间设置得太低,导致经常出现”Timeout waiting for value“异常,把值设置成3000毫秒了就没问题了。


异常信息:

net.spy.memcached.OperationTimeoutException: Timeout waiting for value
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1133)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1148)
...(忽略中间)...
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: /127.0.0.1:11211
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:160)
at net.spy.memcached.internal.GetFuture.get(GetFuture.java:62)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1123)
... 35 more


参考资料:

http://www.iteye.com/problems/69586

http://code.google.com/p/spymemcached/issues/detail?id=136

http://blog.csdn.net/fhd001/article/details/6764542