Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection to remote redis server is reset

Trying the basic set operation on a redis server installed in red hat linux.

        JedisPool pool = new JedisPool(new JedisPoolConfig(), HOST, PORT);

        Jedis jedis = null;
        try {
          jedis = pool.getResource();

          System.out.println(jedis.isConnected()); //prints true

          jedis.set("status", "online"); //gets exception

        } finally {
          if (jedis != null) {
            jedis.close();
          }
        }

        pool.destroy();

Getting the following exception:

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Connection reset
    at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:201)
    at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
    at redis.clients.jedis.Protocol.process(Protocol.java:132)
    at redis.clients.jedis.Protocol.read(Protocol.java:196)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:288)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:187)
    at redis.clients.jedis.Jedis.set(Jedis.java:66)
    at com.revechat.spring.redis_test.App.main(App.java:28)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:195)
    ... 7 more

How to resolve the issue ?

like image 917
Md. Arafat Al Mahmud Avatar asked May 26 '15 06:05

Md. Arafat Al Mahmud


1 Answers

I had a similar issue. Our production Redis required an encrypted connection over TLS, whereas our test system did not. In production therefore the java.net.SocketException: Connection reset appeared when we tried to use the Jedis connection.

To fix it, use

JedisPool pool = new JedisPool(new JedisPoolConfig(), HOST, PORT, true);

for connections that require TLS.

like image 195
Erica Kane Avatar answered Sep 30 '22 09:09

Erica Kane