在windows配置redis的一些错误及解决方案

目录

[Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException:用客户端Redis Desktop Manager一样的密码端口,是可以正常连接的,但是运行java程序之后使用接口请求就会报错](#Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException:用客户端Redis Desktop Manager一样的密码端口,是可以正常连接的,但是运行java程序之后使用接口请求就会报错)

[Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379](#Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379)


首先引入相关的依赖:我使用的springBoot版本是 2.5.2

XML 复制代码
<!-- 提供Redis连接池 -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
bash 复制代码
spring: 
    # redis配置 
    redis:
        # Redis数据库索引(默认为0)
        database: 1
        # Redis服务器地址
        host: 127.0.0.1
        # Redis服务器连接端口
        port: 6379
        # Redis服务器连接密码(默认为空)
        password: root
        # 连接超时时间
        timeout: 10s
        lettuce:
            pool:
                # 连接池最大连接数
                max-active: 200
                # 连接池最大阻塞等待时间(使用负值表示没有限制)
                max-wait: -1ms
                # 连接池中的最大空闲连接
                max-idle: 10
                # 连接池中的最小空闲连接
                min-idle: 0

Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException:

用客户端Redis Desktop Manager一样的密码端口,是可以正常连接的,但是运行java程序之后使用接口请求就会报错

运行遇到的几个问题:

1、Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException:

用客户端Redis Desktop Manager一样的密码端口,是可以正常连接的,但是运行java程序之后使用接口请求就会报错,所以对配置文件redis.conf进行如下修改:

bash 复制代码
1. 修改protected-mode配置的值为no

protected-mode 是 Redis 配置文件中的一个选项,用于控制 Redis 是否启用保护模式。当 protected-mode 设置为 yes 时,表示 Redis 处于保护模式,只能通过本地回环地址(127.0.0.1)来访问 Redis 服务,即只允许本地客户端进行连接,而不允许外部网络访问。

bash 复制代码
2. 注释#bind 127.0.0.1

默认情况下,bind 设置为空,表示 Redis 监听所有可用的网络接口,包括本地127.0.0.1和外部网络地址。这意味着 Redis 可以接受来自任何网络接口的连接。当将 bind 设置为具体的 IP 地址或主机名时,Redis 将仅监听指定的网络接口,而不再监听其他网络接口。例如,如果将 bind 设置为 127.0.0.1,则 Redis 只会监听本地回环地址,即只允许本地客户端进行连接,而拒绝来自外部网络的连接。

bash 复制代码
3. 增加redis连接密码

在redis.conf配置文件中搜索requirepass,就可以添加密码了:

然后重新启动redis就行。

上面都配置好后,但是还是报错,报错内容如下:

"Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379

Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379

原因是配置文件有问题,刚刚我们的配置文件是:

需要把password修改为 auth:

bash 复制代码
  redis:
    database: 0
    host: localhost
    port: 6379
    auth: abc123456

这样就可以正常访问了!

相关推荐
一品人家3 小时前
win32汇编使用GDI+入门教程之九
汇编·windows·win32汇编
fen_fen6 小时前
Oracle建表语句示例
数据库·oracle
砚边数影8 小时前
数据可视化入门:Matplotlib 基础语法与折线图绘制
数据库·信息可视化·matplotlib·数据可视化·kingbase·数据库平替用金仓·金仓数据库
orange_tt8 小时前
Djiango配置Celery
数据库·sqlite
小天源9 小时前
Error 1053 Error 1067 服务“启动后立即停止” Java / Python 程序无法后台运行 windows nssm注册器下载与报错处理
开发语言·windows·python·nssm·error 1053·error 1067
云小逸9 小时前
【nmap源码学习】 Nmap网络扫描工具深度解析:从基础参数到核心扫描逻辑
网络·数据库·学习
肉包_5119 小时前
两个数据库互锁,用全局变量互锁会偶发软件卡死
开发语言·数据库·c++
霖霖总总9 小时前
[小技巧64]深入解析 MySQL InnoDB 的 Checkpoint 机制:原理、类型与调优
数据库·mysql
ALex_zry10 小时前
Redis Cluster 分布式缓存架构设计与实践
redis·分布式·缓存
十五年专注C++开发10 小时前
MinHook:Windows 平台下轻量级、高性能的钩子库
c++·windows·钩子技术·minhook