1

I'm using ReactiveRedisConnection to configure a connection to a local redis container.

But in the future the application will be hosted on a webserver and the redis on a different server.

Is there any option to set a timeout for a request?

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
Johnnes Souza
  • 361
  • 1
  • 8
  • 22

2 Answers2

1

After some research and tests, I found that the timeout must be set on the request query instead.

So on the config Class:

@Bean
public ReactiveRedisTemplate<String, String> reactiveRedisTemplateString
(ReactiveRedisConnectionFactory connectionFactory) {
    return new ReactiveRedisTemplate<>
              (connectionFactory, RedisSerializationContext.string());
}

and in the service:

@Autowired
private ReactiveRedisTemplate<String, Response> repository;
public Mono<String> execute(String value){
        return repository.opsForHash().entries("KEY_TO_SEARCH")
                .timeout(Duration.ofMillis(TIMEOUT))
                .collect(Collectors.toMap("CODE_HERE");

Edit: Thank for everyone who helped here.

Johnnes Souza
  • 361
  • 1
  • 8
  • 22
0

Timeout can be configured on your Reactive Connection Implementation. If you are using Lettuce for Redis Connection, you can do the following.

@Bean
public ReactiveRedisConnectionFactory reactiveRedisConnectionFactory() {
    return new LettuceConnectionFactory(new RedisStandaloneConfiguration(), LettuceClientConfiguration.builder().commandTimeout(Duration.ofSeconds(2)).build());
}

And then use the connectionFactory to create ReactiveRedisTemplate.

@Bean
public ReactiveRedisTemplate<String, String> reactiveRedisTemplateString
  (ReactiveRedisConnectionFactory connectionFactory) {
    return new ReactiveRedisTemplate<>(connectionFactory, RedisSerializationContext.string());
}
shazin
  • 21,379
  • 3
  • 54
  • 71