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.BinaryClient.set(BinaryClient.java:110)
at redis.clients.jedis.Client.set(Client.java:47)
at redis.clients.jedis.Jedis.set(Jedis.java:120)
at com.lsy.jedis.JedisDemo1.demo1(JedisDemo1.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
先说问题:使用jedis连接Redis时,下面显示连接超时,爆红;
redis中报错 Redis Creating Server TCP listening socket 32.155.175.175:6379: unable to bind socket, 是redis.conf中闲置了其他ip地址的访问.
解决办法:
步骤一:修改redis.conf的配置文件
在 redis.conf 中找到 bind 127.0.0.1
直接将 bind 127.0.0.1 改为 bind 0.0.0.0
步骤二:修改完配置文件,进入redis中,终止redis,不终止不会生效;
127.0.0.1:6379> shutdown
not connected> exit
步骤三:重启redis
[root@ls bin]# ./redis-server ../conf/redis.conf
3311:C 07 Jun 2022 20:53:50.497 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3311:C 07 Jun 2022 20:53:50.498 # Redis version=5.0.14, bits=64, commit=00000000, modified=0, pid=3311, just started
3311:C 07 Jun 2022 20:53:50.498 # Configuration loaded
这种办法可以解决跨ip访问的问题,其它问题可以检查一下防火墙;