skip to Main Content

when I restart redis cause
java.util.concurrent.ExecutionException: io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
Why is this a problem
use version like this

@Configuration
public class RedisConfig {

    @Autowired
    private RedisProperties redisProperties;

    @Bean(destroyMethod = "close")
    public StatefulRedisConnection<String, Object> StatefulRedisConnection() {
        RedisURI redisUri = RedisURI.builder().withPassword(redisProperties.getPassword())
                .withSentinel(redisProperties.getSentinel().getNodes().get(0).split(":")[0],
                        Integer.valueOf(redisProperties.getSentinel().getNodes().get(0).split(":")[1]))
                .withSentinelMasterId(redisProperties.getSentinel().getMaster())
                .withDatabase(redisProperties.getDatabase()).build();
        RedisClient redisClient = RedisClient.create(redisUri);
        return redisClient.connect(new SerializedObjectCodec());
    }
}
public class CacheImpl implements Cache {
    @Autowired
    private StatefulRedisConnection connect;

    public Boolean addCourseInfosCache() {
        RedisAsyncCommands<String, Object> commands = connect.async();
        // disable auto-flushing
        commands.setAutoFlushCommands(false);
        List<RedisFuture<?>> futures = Lists.newArrayList();
        commands.flushCommands();
    }
}

3

Answers


  1. Lettuce leverages a custom syntax for Redis URIs. This is the schema:

    redis :// [password@] host [: port] [/ database]
      [? [timeout=timeout[d|h|m|s|ms|us|ns]]
      [&_database=database_]]
    

    There are four URI schemes:

    • redis – a standalone Redis server
    • rediss – a standalone Redis server via an SSL connection
    • redis-socket – a standalone Redis server via a Unix domain socket
    • redis-sentinel – a Redis Sentinel server

    The Redis database instance can be specified as part of the URL path or as an additional parameter. If both are supplied, the parameter has higher precedence.

    Print your redis uri connection string and check with your inputs.

    Login or Signup to reply.
  2. You can upgrade Lettuce version and try:

    RedisURI redisUri = RedisURI.Builder.sentinel("sentinelhost1", "mymaster").withPassword("abc").build();
    
    
    Login or Signup to reply.
  3. For me, problem because version of spring and redis (2.1.4), after upgrade newer version, it work normal Please use with:

       <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.3.9.RELEASE</version>
        </parent>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
        <version>2.3.9.RELEASE</version>
    </dependency>
    

    I use redis sentinel and my properties is:

    spring.redis.database=0
    spring.redis.sentinel.master=
    spring.redis.sentinel.nodes=
    spring.redis.sentinel.password=
    spring.redis.password=
    spring.redis.timeout=60000
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search