JedisConnectionException: java.net.SocketTimeoutException:

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out

at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.Connection.sendCommand(Connection.java:126)
at redis.clients.jedis.Connection.sendCommand(Connection.java:121)

Java代码连接 Redis 异常解决方案

  1. xhsell中:检查reids是否启动

ps -aux|grep redis

在这里插入图片描述
2. 检查 虚拟机 / 服务器 防火墙是否关闭

firewall-cmd --state

如下图显示已关闭
在这里插入图片描述

  1. 如果显示running则没有关闭防火墙, 执行以下命令永久关闭防火墙

systemctl disable firewalld.service

  1. 关闭完防火墙,一定要重启才有效

reboot

  1. redis保护模式必须关闭, 编辑redis的配置文件 redis.conf

vim redis.conf

输入以下命令显示行号

:set nu

如果是 redis 5 / 4 在 69bind 127.0.0.1 前面加 #注释
在这里插入图片描述
找到 88 行,将 protected-mode yes 改为 no
在这里插入图片描述
修改完后, 保存退出

:wq!

重启 redis 服务

关闭 redis : redis-cli shutdown
启动 redis : redis-server

此时 redis 连接问题已经解决

感谢阅读, 如果文章对你有帮助记得点赞 收藏 + 关注哦 ! 各种疑难杂症QQ交流群:1101584918,欢迎大家加入。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Lance_welcome/article/details/106392059