【问题标题】:NOAUTH Authentication required spring-boot-data-redis+Realease Lettuce+Redis sentinelNOAUTH 需要认证 spring-boot-data-redis+Realease Lettuce+Redis sentinel
【发布时间】:2021-03-20 12:13:35
【问题描述】:

当我重新启动 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


    【解决方案1】:

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

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

    有四种 URI 方案:

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

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

    打印您的 redis uri 连接字符串并检查您的输入。

    【讨论】:

      【解决方案2】:

      你可以升级Lettuce版本试试:

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

      【讨论】:

        猜你喜欢
        • 2016-01-19
        • 2020-03-16
        • 2017-07-17
        • 2018-06-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-18
        • 1970-01-01
        • 2018-07-06
        相关资源
        最近更新 更多