Redis version: 3.2.0 Jedis version: 2.8.1
Below is my java code for connecting to redis:
public class TestRedis { public static void main(String[] args) { String host = args[0]; int port = Integer.parseInt(args[1]); try (Jedis jedis = new Jedis(host, port)) { System.out.println("Connected to jedis " + jedis.ping()); } catch(Exception e){ e.printStackTrace(); } } } I am running this program on the machine where redis is installed. The public IP address is 192.168.1.57
If I provide host="localhost" and port = "6379" as arguments, then I can successfully connect with redis.
However, If I give host="192.168.1.57" and port = "6379" in arguments, I end up with the following exception:
redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused at redis.clients.jedis.Connection.connect(Connection.java:164) at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:80) at redis.clients.jedis.Connection.sendCommand(Connection.java:100) at redis.clients.jedis.Connection.sendCommand(Connection.java:95) at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:93) at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:105) at TestRedis.main(TestRedis.java:14) Caused by: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at redis.clients.jedis.Connection.connect(Connection.java:158) ... 6 more Please help...