“ JedisConnectionException:连接被同级重置:套接字写入错误”-使用Sentinel时

时间:2018-07-01 07:45:51

标签: java redis jedis redis-sentinel

我的应用程序使用jedis 2.9.0作为其Redis/Sentinel客户端:

JedisSentinelPool sentinelPool = new JedisSentinelPool(masterName, sentinels);
Jedis jedis = sentinelPool.getResource();

我注意到,如果应用长时间闲置,然后尝试从Redis / Sentinel获取数据,则对等方会重置连接:

ERROR 9948 --- [nio-8888-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : 
     Servlet.service() for servlet [dispatcherServlet] in context with path 
     [] threw exception [Request processing failed; nested exception is 
     com.google.common.util.concurrent.UncheckedExecutionException: 
     redis.clients.jedis.exceptions.JedisConnectionException: 
     java.net.SocketException: Connection reset by peer: socket write 
     error] with root cause
java.net.SocketException: Connection reset by peer: socket write error
 at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_161]
 at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111) ~ 
        [na:1.8.0_161]
 at java.net.SocketOutputStream.write(SocketOutputStream.java:155) ~ 
        [na:1.8.0_161]
at redis.clients.util.RedisOutputStream.flushBuffer(RedisOutputStream.java:52) ~[jedis-2.9.0.jar:na]
at redis.clients.util.RedisOutputStream.flush(RedisOutputStream.java:216) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.Connection.flush(Connection.java:331) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.Connection.getIntegerReply(Connection.java:263) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.Jedis.llen(Jedis.java:897) ~[jedis-2.9.0.jar:na]

引发该异常后,该应用程序立即重新连接到Sentinel,并与之顺利运行。

我一直在keep alive = trueJedisSentinelPool中寻找类似Jedis的选项,但直到现在都找不到。

这是正确的路径吗?

0 个答案:

没有答案