我有带有 springboot 2.3.9.RELEASE 的生菜客户端来连接 AWS redis elasticcache master/slave。我能够读写,但每 5000 毫秒会抛出一个错误
该服务适用于我的 pourpose,但我想删除错误或如何知道如何修复它。
我已经阅读了很多关于它的内容,使用生菜和 AWS 配置 spring 数据 redis 的最佳方法是使用 RedisStaticMasterReplicaConfiguration 写入主服务器并从副本读取。
这是bean配置
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
LettuceClientConfiguration.LettuceClientConfigurationBuilder lettuceConfigBuilder = LettuceClientConfiguration.builder()
.readFrom(ReadFrom.REPLICA_PREFERRED);
lettuceConfigBuilder.useSsl();
RedisStaticMasterReplicaConfiguration redisConfiguration = new RedisStaticMasterReplicaConfiguration(master, port); //master value is the Primary Endpoint value from aws elasticcache info
redisConfiguration.addNode(replica, port); //replica value is the Reader Endpoint value from aws elasticcache info
redisConfiguration.setPassword(password);
return new LettuceConnectionFactory(redisConfiguration, lettuceConfigBuilder.build());
}
当应用程序启动时,我可以读写,但每 5 秒就会从 RedisMessageListenerContainer 抛出一个错误
"level":"ERROR","className":"org.springframework.data.redis.listener.RedisMessageListenerContainer","message":"Connection failure occurred. Restarting subscription task after 5000 ms "
但这是来自 RedisMessageListenerContainer.handleSubscriptionException 的原始错误
java.lang.UnsupportedOperationException: Pub/Sub connections not supported with Master/Replica configurations