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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With