0

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?

Savitar
  • 1
  • 1
  • You say you are "having trouble" - what exactly is going wrong? (What is the current result?) – ryanwebjackson Mar 28 '23 at 21:43
  • 1
    @ryanwebjackson If I understand correctly, my application is currently connecting directly to the Redis Master node in my Application.yml configuration, bypassing 3 Sentinel nodes. I don't know how to include the 3 Sentinel nodes in my application configuration. – Savitar Mar 29 '23 at 17:19
  • @ryanwebjackson : I updated my post and now my application is throwing a specific error. – Savitar Mar 30 '23 at 09:08

1 Answers1

0

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

Savitar
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 08 '23 at 04:57