jedis连接异常:套接字写错误

时间:2014-07-30 13:16:40

标签: java redis jedis

使用jedis客户端将数据保存到redis localhost。

一旦我使用jedis连接到redisHost,只要我收到消息,我就不会断开连接这是一个问题吗?试图将超时从默认2000更改为6000,但仍然是相同的错误!

连接和发送数据:

if (jedis == null)
      jedis = new Jedis(redisHost);

if (!jedis.isConnected())
      jedis.connect();

if (jedis.isConnected()) 
      jedis.zadd("someKey", doubleTime, "someValue");

以下是错误接收的堆栈跟踪:

    redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Software caused connection abort: socket write error
    at redis.clients.jedis.Protocol.sendCommand(Protocol.java:92)
    at redis.clients.jedis.Protocol.sendCommand(Protocol.java:72)
    at redis.clients.jedis.Connection.sendCommand(Connection.java:80)
    at redis.clients.jedis.BinaryClient.zadd(BinaryClient.java:387)
    at redis.clients.jedis.Client.zadd(Client.java:327)
    at redis.clients.jedis.Jedis.zadd(Jedis.java:1468)
    at com.comcast.xre.WebSocketServer.saveLogToDB(WebSocketServer.java:105)
    at com.comcast.xre.WebSocketServer.access$000(WebSocketServer.java:27)
    at com.comcast.xre.WebSocketServer$1$1.onFullTextMessage(WebSocketServer.java:69)
    at io.undertow.websockets.core.AbstractReceiveListener$2.complete(AbstractReceiveListener.java:138)
    at io.undertow.websockets.core.AbstractReceiveListener$2.complete(AbstractReceiveListener.java:134)
    at io.undertow.websockets.core.BufferedTextMessage.read(BufferedTextMessage.java:87)
    at io.undertow.websockets.core.AbstractReceiveListener.readBufferedText(AbstractReceiveListener.java:134)
    at io.undertow.websockets.core.AbstractReceiveListener.bufferFullMessage(AbstractReceiveListener.java:72)
    at io.undertow.websockets.core.AbstractReceiveListener.onText(AbstractReceiveListener.java:52)
    at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:26)
    at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:15)
    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
    at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:632)
    at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:618)
    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
    at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
    at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:87)
    at org.xnio.nio.WorkerThread.run(WorkerThread.java:531)
Caused by: java.net.SocketException: Software caused connection abort: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
    at redis.clients.util.RedisOutputStream.flushBuffer(RedisOutputStream.java:31)
    at redis.clients.util.RedisOutputStream.write(RedisOutputStream.java:38)
    at redis.clients.jedis.Protocol.sendCommand(Protocol.java:78)
    ... 23 more

1 个答案:

答案 0 :(得分:1)

问题出在Jedis连接上。它已连接,但在几条消息之后,连接断开。 每次保存到DB后,我将完全断开连接并删除jedis客户端并创建新的客户端和连接。看起来很尴尬,但它解决了这个问题。