当前位置: 首页 > news >正文

Spring Boot集成Redis并设置密码后报错: NOAUTH Authentication required

报错信息:

io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.

Redis密码配置确认无误,但是只要使用Redis存储就报这个异常。很可能是因为配置的spring.redis.password没有被读取到。



基本依赖:

implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

基本设置(application.properties):

spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=your_password
spring.redis.database=0
spring.redis.timeout=3000


解决方法:

@Configuration
public class RedisConfig {

    @Value("${spring.redis.password}")
    private String redisPassword;
    @Value("${spring.redis.host}")
    private String redisHost;
    @Value("${spring.redis.port}")
    private int redisPort;

    /**
     * 解决redis认证报错问题:io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
     *
     * @return
     */
    @Bean
    public LettuceConnectionFactory redisConnectionFactory() {
        return new LettuceConnectionFactory(
                new RedisStandaloneConfiguration(redisHost, redisPort) {{
                    setPassword(RedisPassword.of(redisPassword));
                }});
    }
}
http://www.dtcms.com/a/81999.html

相关文章:

  • 2020年全国职业院校技能大赛改革试点赛高职组“云计算”竞赛赛卷
  • 参数估计学习笔记通俗易懂版(包括点估计和区间估计(区间估包括总体均值的置信区间(总体标准差未知、总体标准差已知)和总体方差的置信区间))
  • Mybatis能执行一对一、一对多的关联查询吗?都有哪些实现方式,以及它们之间的区别?
  • 【React】useMemo、useCallback
  • 关于VSCode使用过程中的一些问题记录(持续更新)
  • kernel中外部传递参数使用方法
  • 20250321在荣品的PRO-RK3566开发板的buildroot系统下使用UART1
  • 几个JSON在AutoCAD二次开发中应用比较有优势的场景及具体案例
  • 威联通 后台可用命令查看Bash
  • <项目> 主从Reactor模型的高并发服务器
  • Python与区块链隐私保护技术:如何在去中心化世界中保障数据安全
  • vlan实验
  • Python异常简介
  • Manus与Dify差异分析
  • 19.哈希表的实现
  • 【数据结构】kmp算法介绍+模板代码
  • 树莓集团落子海南,解读数字产业新势力
  • 2014-2023年各区县数字普惠金融指数数据
  • 【设计模式】C++ 单例模式总结与最佳实践
  • 3DMAX曲线生成器插件CurveGenerator使用方法
  • C语言【动态内存管理】详解
  • Beans模块之工厂模块注解模块@Qualifier
  • 计算机组成原理和计算机网络常见单位分类及换算
  • 机器学习算法实战——天气数据分析(主页有源码)
  • 算法及数据结构系列 - 树
  • 「AI+办公」共学(四):办公综合应用
  • Python 打造高效开发辅助全能工具箱
  • mysql( 8.3.0) LISTAGG
  • 使用Multiprocessing模块创建子进程,需要放到__main__中
  • 【最后203篇系列】021 Q201再计划