我正在研究Vertx项目,该项目需要访问Redis。这是我正在使用的依赖项:
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-redis-client</artifactId>
<version>3.7.0</version>
</dependency>
我的代码如下:
RedisOptions redisOpts = new RedisOptions()
.setEndpoint(new SocketAddressImpl(AppSettings.REDIS_PORT, AppSettings.REDIS_IP))
.setSelect(AppSettings.REDIS_DB)
.setNetClientOptions(new NetClientOptions().setConnectTimeout(2000));
System.out.println("Connecting to redis: " + redisOpts.getEndpoint());
Redis.createClient(vertx, redisOpts)
.connect(onConnect -> {
if (onConnect.succeeded()) {
System.out.println("Redis got connected");
Redis redisClient = onConnect.result();
AppSettings.REDIS_CLIENT.complete(redisClient);
} else {
onConnect.cause().printStackTrace();
AppSettings.REDIS_CLIENT.fail(onConnect.cause());
}
});
我在测试代码时,会引发以下错误:
io.vertx.core.impl.NoStackTraceThrowable: Redis connection is broken.
有人可以帮助我找到此错误的可能原因吗?顺便说一下,Redis运行正常。