i want to apply spring-session-data-redis to my spring boot project.

but printed log Connection failure occurred. Restarting subscription task after 5000 ms

exception message is Pub/Sub connections not supported with Master/Replica configurations

my redis configuration is

public LettuceConnectionFactory lettuceConnectionFactory() {
    RedisStaticMasterReplicaConfiguration configuration = new RedisStaticMasterReplicaConfiguration(
    MASTER_HOST, MASTER_PORT);
    configuration.addNode(SLAVE_HOST, SLAVE_PORT);
             
    LettuceClientConfiguration clientConfig =
            LettuceClientConfiguration.builder().readFrom(ReadFrom.REPLICA_PREFERRED).build();
        
    return new LettuceConnectionFactory(configuration, clientConfig);
}

developed in aws environment. and my redis environment is write to master, read from replica

So we applied RedisStaticMasterReplicaConfiguration according to the document below.

For environments reporting non-public addresses through the INFO command (for example, when using AWS), use RedisStaticMasterReplicaConfiguration instead of RedisStandaloneConfiguration.

but, it does not support Pub/Sub according to the document below.

Please note that RedisStaticMasterReplicaConfiguration does not support Pub/Sub because of missing Pub/Sub message propagation across individual servers.

have any good ideas?

the strange thing is

printed log Connection failure occurred. Restarting subscription task after 5000 ms

but, It works well.(save and select session at redis)

additional infomation:

trying to connect Pub/Sub by this.

org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration

@Bean
public RedisMessageListenerContainer springSessionRedisMessageListenerContainer(
        RedisIndexedSessionRepository sessionRepository) {
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(this.redisConnectionFactory);
    if (this.redisTaskExecutor != null) {
        container.setTaskExecutor(this.redisTaskExecutor);
    }
    if (this.redisSubscriptionExecutor != null) {
        container.setSubscriptionExecutor(this.redisSubscriptionExecutor);
    }
    container.addMessageListener(sessionRepository,
            Arrays.asList(new ChannelTopic(sessionRepository.getSessionDeletedChannel()),
                    new ChannelTopic(sessionRepository.getSessionExpiredChannel())));
    container.addMessageListener(sessionRepository,
            Collections.singletonList(new PatternTopic(sessionRepository.getSessionCreatedChannelPrefix() + "*")));
    return container;
}
0

There are 0 best solutions below