redis 创建套接字失败
redis failed to create socket
Redis 连接遇到问题。主机和端口已配置,docker 中的 redis 容器工作正常,我不知道为什么会出现此异常。
我如何运行这个测试:
运行 docker 带有 redis 的容器 -> 进入 redis cli 并执行“redis-server”
cli 截图:
经过我运行的测试。
P.S。 redis 在控制台中运行良好
redis 控制台:
测试
@SpringBootTest
class MessengerApplicationTests {
@Test
void contextLoads() {
Jedis jedis = new Jedis();
System.out.println(jedis.keys("*"));
}
}
异常
Failed to create socket.
redis.clients.jedis.exceptions.JedisConnectionException: Failed to create socket.
at app//redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:110)
at app//redis.clients.jedis.Connection.connect(Connection.java:226)
at app//redis.clients.jedis.BinaryClient.connect(BinaryClient.java:140)
at app//redis.clients.jedis.Connection.sendCommand(Connection.java:163)
at app//redis.clients.jedis.BinaryClient.keys(BinaryClient.java:248)
at app//redis.clients.jedis.Client.keys(Client.java:130)
at app//redis.clients.jedis.Jedis.keys(Jedis.java:380)
at app//com.microservice.messenger.MessengerApplicationTests.contextLoads(MessengerApplicationTests.java:22)
at java.base@16.0.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base@16.0.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base@16.0.1/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base@16.0.1/java.lang.reflect.Method.invoke(Method.java:567)
at app//org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at app//org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
application.yml
server:
port: ${SERVER_PORT:3031}
spring:
datasource:
url: jdbc:postgresql://localhost:5432/reg_auth_db
username: postgres
password: postgres
flyway:
url: jdbc:postgresql://localhost:5432/reg_auth_db
user: postgres
password: postgres
rabbitmq:
password: guest
username: guest
port: 15672
redis:
port: 6379
host: localhost
我使用了错误的端口,因为我的企业版有三个不同的端口
Redis 连接遇到问题。主机和端口已配置,docker 中的 redis 容器工作正常,我不知道为什么会出现此异常。
我如何运行这个测试:
运行 docker 带有 redis 的容器 -> 进入 redis cli 并执行“redis-server”
cli 截图:
经过我运行的测试。
P.S。 redis 在控制台中运行良好
redis 控制台:
测试
@SpringBootTest
class MessengerApplicationTests {
@Test
void contextLoads() {
Jedis jedis = new Jedis();
System.out.println(jedis.keys("*"));
}
}
异常
Failed to create socket.
redis.clients.jedis.exceptions.JedisConnectionException: Failed to create socket.
at app//redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:110)
at app//redis.clients.jedis.Connection.connect(Connection.java:226)
at app//redis.clients.jedis.BinaryClient.connect(BinaryClient.java:140)
at app//redis.clients.jedis.Connection.sendCommand(Connection.java:163)
at app//redis.clients.jedis.BinaryClient.keys(BinaryClient.java:248)
at app//redis.clients.jedis.Client.keys(Client.java:130)
at app//redis.clients.jedis.Jedis.keys(Jedis.java:380)
at app//com.microservice.messenger.MessengerApplicationTests.contextLoads(MessengerApplicationTests.java:22)
at java.base@16.0.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base@16.0.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base@16.0.1/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base@16.0.1/java.lang.reflect.Method.invoke(Method.java:567)
at app//org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at app//org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
application.yml
server:
port: ${SERVER_PORT:3031}
spring:
datasource:
url: jdbc:postgresql://localhost:5432/reg_auth_db
username: postgres
password: postgres
flyway:
url: jdbc:postgresql://localhost:5432/reg_auth_db
user: postgres
password: postgres
rabbitmq:
password: guest
username: guest
port: 15672
redis:
port: 6379
host: localhost
我使用了错误的端口,因为我的企业版有三个不同的端口