解决 Redis 报错 NOAUTH Authentication required 密码缺失
分析未输入密码连接 Redis 执行命令报 NOAUTH Authentication required 的排查步骤,提供 AUTH 命令与连接池配置方案。
问题现象
在终端或客户端向 Redis 发送命令时抛出错误:
(error) NOAUTH Authentication required.
除 AUTH 命令外,其他任何操作(如 GET、PING、INFO)均被直接拦截拒绝。
触发根因
- Redis 服务端在
redis.conf中配置了密码认证保护指令(requirepass "MyPassword")。 - 客户端建立了 TCP 连接,但未在发送其他指令前先执行 AUTH 命令提供凭证。
解决步骤与操作命令
步骤一:在命令行中显式通过 AUTH 命令认证
在进入交互模式后立即输入密码:
redis-cli
127.0.0.1:6379> AUTH MyPassword
OK
127.0.0.1:6379> PING
PONG
步骤二:启动 redis-cli 时直接传入 -a 参数
redis-cli -a MyPassword PING
步骤三:在应用程序连接配置中补齐 password 参数
在 Spring Boot、Django、Express 等框架配置中注入密码:
# Spring Boot 示例
spring:
data:
redis:
host: 127.0.0.1
port: 6379
password: MyPassword # 补齐密码字段
验证确认
测试读写命令:
127.0.0.1:6379> SET status "authenticated"
OK
操作顺利完成,未再出现 NOAUTH 报错。


