redisjedisredis-sentinel

Jedis cannot find master using sentinel when sentinel required password


Recently i work with redis and using jedis. In redis version 6, we can set required password mode for sentinels. I have 3 working sentinels, can connect and authen throught redis-cli. But using jedis, i can't connect to the sentinel with this warning:

Cannot get master address from sentinel running @ 127.0.0.1:26379. Reason: redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.. Trying next one.

Cannot get master address from sentinel running @ 127.0.0.1:36379. Reason: redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.. Trying next one.

Cannot get master address from sentinel running @ 127.0.0.1:16379. Reason: redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.. Trying next one.

And this error:

All sentinels down, cannot determine where is mymaster master is running...

Here is my code:

        GenericObjectPoolConfig pc = new GenericObjectPoolConfig();
        pc.setMinIdle(2);
        pc.setMaxIdle(5);
        pc.setMaxTotal(5);
        JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, pc, 1000*10, PASSWORD);
        Jedis jedis = null;
        try {
            printer("Fetching connection from pool");
            jedis = pool.getResource();
            printer("Authenticating...");
            jedis.auth(PASSWORD);
            printer("auth complete...");
            Socket socket = jedis.getClient().getSocket();
            printer("Connected to " + socket.getRemoteSocketAddress());
            printer("Writing...");
            jedis.set("java-key-999", "java-value-999");
            printer("Reading...");
            printer(jedis.get("java-key-999"));
        } catch (JedisException e) {
            printer("Connection error of some sort!");
            printer(e.getMessage());
            Thread.sleep(2 * 1000);
        } finally {
            if (jedis != null) {
                jedis.close();
            }
        }

Please help, thank you for your reading support <3


Solution

  • Your sentinel nodes are password protected. You would have to provide AUTH parameters to connect to sentinel nodes.

    Update:

    Password you're providing acts as the password for master node. To avoid NOAUTH error from sentinel nodes, you have to provide the password for sentinel nodes. Look for any constructor that takes the password for sentinel nodes. That parameter is generally named sentinelPassword. There are several such constructors, simplest of those is

    JedisSentinelPool(String masterName, Set<String> sentinels, String password, String sentinelPassword)
    

    You're welcome to look for other constructor that suits you most.