NOAUTH 需要身份验证 spring-boot-data-redis+Realease Lettuce+Redis Sentinel

问题描述 投票:0回答:3

当我重新启动redis时
java.util.concurrent.ExecutionException:io.lettuce.core.RedisCommandExecutionException:NOAUTH 需要身份验证。 为什么这是个问题 使用这样的版本

@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();
    }
}
java spring-boot redis spring-data-redis lettuce
3个回答
0
投票

Lettuce 利用 Redis URI 的自定义语法。这是架构:

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

有四种 URI 方案:

  • redis – 独立的 Redis 服务器
  • rediss – 通过 SSL 连接的独立 Redis 服务器
  • redis-socket – 通过 Unix 域套接字的独立 Redis 服务器
  • redis-sentinel – Redis Sentinel 服务器

Redis 数据库实例可以指定为 URL 路径的一部分或附加参数。如果两者都提供,则该参数具有更高的优先级。

打印您的 Redis URI 连接字符串并检查您的输入。


0
投票

您可以升级Lettuce版本并尝试:

RedisURI redisUri = RedisURI.Builder.sentinel("sentinelhost1", "mymaster").withPassword("abc").build();


0
投票

对我来说,问题是因为spring和redis的版本(2.1.4),升级新版本后,它工作正常请使用:

   <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>

我使用redis哨兵,我的属性是:

spring.redis.database=0
spring.redis.sentinel.master=
spring.redis.sentinel.nodes=
spring.redis.sentinel.password=
spring.redis.password=
spring.redis.timeout=60000
© www.soinside.com 2019 - 2024. All rights reserved.