Unable to connect to redis using jedis

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 run this program on the machine where redis is installed. This device IP address is 192.168.1.57

If I provide host = "localhost" and port = "6379" as arguments, the connection to redis is successfully established.

However, if I give host = "192.168.1.57" and port = "6379" in the arguments, I get 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...

+6
source share
1 answer

: . , .

redis.conf :

bind 127.0.0.1

# :

# bind 127.0.0.1

, , IP eth0/em1, :

bind 127.0.0.1 192.168.1.57

, , , :

protected-mode yes

, :

protected-mode no

.

Redis.

+5

All Articles