title: NOAUTH Authentication required when connecting to Redis Sentinel with LettuceConnectionFactory
body: <p>I am trying to connect to a Redis server using sentinel with password. I got RedisCommandExecutionException: NOAUTH Authentication required when calling <code>redisTemplate.opsForValue().get("key")</code></p>
  
  <pre><code>Exception in thread "Thread-6" org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis on localhost:6379; nested exception is com.lambdaworks.redis.RedisCommandExecutionException: NOAUTH Authentication required.
      at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.createLettuceConnector(LettuceConnectionFactory.java:544)
      at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.initConnection(LettuceConnectionFactory.java:213)
      at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:517)
      at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:189)
  </code></pre>
  
  <p>This is how I configured the connection factory:</p>
  
  <pre class="lang-java prettyprint-override"><code>RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration().master("mymaster").sentinel("localhost", 26379);
  LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(sentinelConfiguration);
  lettuceConnectionFactory.setDatabase(1);
  lettuceConnectionFactory.setPassword("foobared");
  </code></pre>
  
  <p>When I tried using <code>JedisConnectionFactory</code>, it works.</p>
  
  <p>It looks like the password is not set when using <code>LettuceConnectionFactory</code> with sentinel.</p>
  
  <p>I'm using spring-data-redis 1.7.2.</p>
  
  <p>UPDATE:</p>
  
  <p>I checked the code in <code>DefaultLettucePool</code> and saw that the password is not used in generating <code>RedisURI</code> when sentinelConfiguration is involved. When I modified the code as following, it works now.</p>
  
  <p>DefaultLettucePool:</p>
  
  <pre class="lang-java prettyprint-override"><code>private RedisURI getRedisURI() {
  
      if (isRedisSentinelAware()) {
          return LettuceConverters.sentinelConfigurationToRedisURI(sentinelConfiguration, password, getDatabase());
      }
  
      return createSimpleHostRedisURI();
  }
  </code></pre>
  
  <p>And in LettuceConverters:</p>
  
  <pre class="lang-java prettyprint-override"><code>public static RedisURI sentinelConfigurationToRedisURI(RedisSentinelConfiguration sentinelConfiguration, String password, int database) {
      Assert.notNull(sentinelConfiguration, "RedisSentinelConfiguration is required");
  
      Set&lt;RedisNode&gt; sentinels = sentinelConfiguration.getSentinels();
      RedisURI.Builder builder = null;
      for (RedisNode sentinel : sentinels) {
  
          if (builder == null) {
              builder = RedisURI.Builder.sentinel(sentinel.getHost(), sentinel.getPort(), sentinelConfiguration.getMaster()
                      .getName());
          }
          else {
              builder.withSentinel(sentinel.getHost(), sentinel.getPort());
          }
      }
  
      if (password != null) {
          builder = builder.withPassword(password);
      }
      builder.withDatabase(database);
  
      return builder.build();
  }
  </code></pre>