NutzCN Logo
问答 org.nutz.integration.jedis.RedisInterceptor.jedis 报连接超时,请问是原因,查了好久了。
发布于 279天前 作者 netexe 274 次浏览 复制 上一个帖子 下一个帖子
标签:
import static org.nutz.integration.jedis.RedisInterceptor.jedis;

@IocBean
public class RedisImpl {

  @Aop("redis")
  public boolean addObj(String key, Object info) {
    try {
      String objstr = JSON.toJSONString(info);
      jedis().set(key, objstr);
      return true;
    }catch (Exception e)
    {
      e.printStackTrace();
      return false;
    }
  }

报错的日志:

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
	at redis.clients.jedis.Connection.flush(Connection.java:334)
	at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:237)
	at redis.clients.jedis.Jedis.set(Jedis.java:121)
	at org.xxxxxx.utils.RedisImpl.addObj(RedisImpl.java:44)
	at org.xxxxxx.utils.RedisImpl$$NUTZAOP._aop_invoke(RedisImpl.java)
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
	at org.nutz.integration.jedis.RedisInterceptor.filter(RedisInterceptor.java:24)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at org.xxxxxx.utils.RedisImpl$$NUTZAOP.addObj(RedisImpl.java)
	at org.xxxxxx.modules.api.MainApiModule.login(MainApiModule.java:373)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:22)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:99)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:40)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:64)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:94)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.xxxxxx.common.filters.XSSFilter.doFilter(XSSFilter.java:24)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:662)
Caused by: java.net.SocketTimeoutException: Read timed out
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.read(SocketInputStream.java:129)
	at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:422)
	at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:460)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:863)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1188)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:654)
	at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:100)
	at redis.clients.util.RedisOutputStream.flushBuffer(RedisOutputStream.java:52)
	at redis.clients.util.RedisOutputStream.flush(RedisOutputStream.java:216)
	at redis.clients.jedis.Connection.flush(Connection.java:331)
	... 44 more

以下代码是可以连接的:

  public static void main(String[] paramArrayOfString){
    String HOST = "localhost";
    int PORT = 6379;
    Jedis jedis = new Jedis(HOST, PORT);
    try {
      jedis.set("foo", "bar");
      jedis.get("foo");
      System.out.println("Redis read/write ok.");
    } catch (Exception e) {
      System.err.println("Unable to connect to Redis");
      e.printStackTrace();
    }
  }
15 回复

环境:
JDK 1.6
jedis-2.9.0.jar
commons-pool2-2.4.2.jar
nutz-integration-jedis-1.r.63.r4.jar (是我用JDK1.6编译出来的)

检查一下redis.properties

老大这么晚了还在。。。
提醒我了,
改成 redis.database=0 可以用了。
但是原来在 JDK1.8 环境,redis.database=1也是可以用的。
请问老大这个是什么原因?

redis.host=localhost
redis.port=6379
redis.timeout=2000
#redis.password=
redis.database=0
#redis.mode=cluster

@netexe 不像这个原因

redis版本多少

JDK 1.6
nutz-1.b.49-jdk1.6.jar
nutz-integration-jedis-1.r.63.r4-jdk1.6.jar
Redis 3.2.100 64 bit, standalone mode, port 6379 (Windows 10 64位)

JDK 1.8 的时候确实可以使用 database=1

题外话:
nutz的版本有点低,老的应用系统要加redis缓存功能,升级到 nutz 1.r.63 又一堆问题,没法子。

哦,那就先用着吧

谢谢。顺便问一下,有什么插件可以配置nutz-integration-jedis做超时管理的?

指什么的超时呢?

redis.timeout=1000 这个?

redis缓存超时,比如一个token登录以后,20分钟没有动作自动清理的。

那是redis的命令啊,可以设置过期时间的

我是小白,见笑了。。。

JDK 1.6, redis dbIndex = 1 时,
需要使用 jedis 2.8.x 版本,
jedis 2.9 会连接不上

添加回复
请先登陆
回到顶部