如何解决在 redis 哨兵上使用 asyncRedisCommands 的 Redis 生菜设置
我的设置如下:
- 我正在 spring 应用程序上运行此设置。
- 我正在使用生菜模块的 RedisAsyncCommands。我能够使用独立的 Redis 配置运行它。
- 当我尝试使用哨兵模式运行它时,它在初始春季启动过程中卡住了。
- 我可以使用手动创建对象的方式击中同一个哨兵 终端应用。但是当我尝试使用 spring boot 时它失败了。
下面是卡住的阶段。
2021-06-25 02:48:57,328 38486 [main] INFO [i.l.c.EpollProvider] {{clusterName,default}{appResourceId,ss@dev}} - Starting without optional epoll library
2021-06-25 02:48:57,331 38489 [main] INFO [i.l.c.KqueueProvider] {{clusterName,ss@dev}} - Starting without optional kqueue library
我已经对其进行了仔细调试,看起来问题是在它尝试连接到哨兵服务器时出现的。它正在尝试调用 AbstractRedisClient 类,但无法建立连接。
protected <T> T getConnection(ConnectionFuture<T> connectionFuture) {
try {
return connectionFuture.get();
} catch (InterruptedException var3) {
Thread.currentThread().interrupt();
throw RedisConnectionException.create(connectionFuture.getRemoteAddress(),var3);
} catch (Exception var4) {
if (var4 instanceof ExecutionException) {
throw RedisConnectionException.create(connectionFuture.getRemoteAddress(),var4.getCause());
} else {
throw RedisConnectionException.create(connectionFuture.getRemoteAddress(),var4);
}
}
}
在 coonectionFuture.get() 行失败。
我的bean配置:
@Bean
public RedisClient redisClient() {
return RedisClient.create(RedisURI.builder()
.withSentinel("localhost",26379)
.withSentinel("localhost",5000)
.withSentinel("localhost",5001)
.withSentinelMasterId("mymaster").build());
}
@Bean
public StatefulRedisConnection<String,String> statefulRedisConnection(final RedisClient redisClient) {
return redisClient.connect();
}
@Bean
public RedisAsyncCommands<String,String> redisAsyncCommands(
final StatefulRedisConnection<String,String> redisConnection
) {
return redisConnection.async();
}
我将使用下面的 async 对象来运行 async.hget()、async.set() 等命令。
private final RedisClient redisClientNew;
private final StatefulRedisConnection<String,String> connection;
private final RedisAsyncCommands<String,String> async;
非常感谢任何帮助,如果需要,请告诉我任何额外信息。如果您对此有任何想法或可以帮助我进行设置,请发表评论。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。