skip to Main Content

I currently have a running application with Redis and I would like to add Redis Sentinel configuration to ensure high availability for my database. Could someone help me with configuring Redis Sentinel in Micronaut?

Application.yml file:

redis:
  uri: redis-sentinel://localhost:26379,localhost:26380,localhost:26381/0#redismaster

My main code file:

public class MyRedisRepository {

    private final RedisClient client;

    @Inject
    public MyRedisRepository (RedisClient client) {
        this.client = client;
    }

    public void save(String message) {
        StatefulRedisConnection<String, String> connection = client.connect();

        try {

            connection.sync().set("my-key", message);

            if (connection.sync().exec().wasDiscarded()) {
                log.error("While trying to save message Redis transaction has been discarded.");
            }
        } catch (Exception exc) {
            log.error("Exception occurred while saving message. Transaction discarded: {}", connection.sync().discard(), exc);
        }
    }    
}

In Docker, I have running:

  • 3 Sentinel nodes (172.21.0.4, 172.21.0.5, 172.21.0.7)
  • 1 Redis Master node (172.21.0.2)
  • 1 Redis Slave node 172.21.0.3)

Unfortunately, my application is not working as expected and is throwing an error:

Error starting Micronaut server: Unable to connect to 172.21.0.2:6379

where 172.21.0.2 is IP Redis Master Contatainer

How can I solve this problem?

2

Answers


  1. Chosen as BEST ANSWER

    Unfortunately, I managed to establish the connection only after migrating to Kubernetes and changing the library to Jedis (allowing the use of certificates).


  2. Did you find a solution for Micronaut and sentinel? Cause I have the same issue and error

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search