Cannot connect to redis through Jedis

Look at the code first:

package com.cc;

import redis.clients.jedis.Jedis;

public class TestPing {
    
    
    public static void main(String[] args) {
    
    
        Jedis jedis = new Jedis("39.99.145.221",6379);
        System.out.println(jedis.ping());
    }
}

If you can connect to redis, it is PONG.
The result is not satisfactory.

Solution:
Most of these problems are caused by firewalls.
But you have to make sure that your redis.conf configuration file is bind 127.0.0.1commented out and protected-mode yeschanged to ·no·.
There is another point to open the 6379 port of your Alibaba Cloud security group.
Check the firewall problem again.
Solution 1: Turn off the firewall .

#查看防火墙的状态
systemctl status firewalld
#关闭防火墙
systemctl stop firewalld

I used to use iptables, but after centos7.0 it was replaced with firewalled.
First check the status of firewalled, the following is in operation.
Insert picture description here
Try to close. systemctl stop firewalld, The picture below is the closed state. Then go to test the connection.
Insert picture description here

Solution 2: Turn on the firewall and open port 6379.

Open the firewall first, and then open port 6379.

#开启6379端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent

Insert picture description here
The firewall needs to be restarted below.

#重启防火墙
systemctl restart firewalld

Insert picture description here
Then carry out the connection test.

After you have tried the first solution and still cannot connect, don't be discouraged. Try the second solution and it may work.
I connected the first way at noon today, but I couldn't connect again in the afternoon, and I tried the second way again. Very speechless!

Guess you like

Origin blog.csdn.net/hello_cmy/article/details/106078838