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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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());
}

1 Comment

Whatever I set, it is taking 10 seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.