3.1K Star 33.5K Fork 23.7K

若依 / RuoYi-Vue

 / 详情

exception is io.lettuce.core.RedisException: java.io.IOException: 远程主机强迫关闭了一个现有的连接。

已完成
创建于  
2019-11-14 16:10

org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: java.io.IOException: 远程主机强迫关闭了一个现有的连接。

说明:不影响使用但是经常会报错导致前端需要重新操作

评论 (7)

wuming 创建了任务

配置redis超时时间

相同问题,请问是配置redis的配置文件redis.conf中的tcp-keepalive?还是改项目中的配置application.yml中的redis.timeout:60s?

若依 任务状态待办的 修改为已完成

我也遇到了一摸一样的问题,请问作者具体的做法是什么呢

自己安装的redis服务目录下有redis.xxxx.conf文件,设置timeout 0即可。
@wuming @排骨爱米饭 @rocgege @尹雄标

我的另外项目没有这种情况,但是在若依里边存在这个问题。下边的代码可以暂时解决这个问题

import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class LettuceConnectionValidConfig implements InitializingBean {

    @Resource
    RedisConnectionFactory redisConnectionFactory;

    @Override
    public void afterPropertiesSet() {
        if (redisConnectionFactory instanceof LettuceConnectionFactory) {
            LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) redisConnectionFactory;
            connectionFactory.setValidateConnection(true);
        }
    }
}

import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class LettuceConnectionValidTask {


    @Resource
    RedisConnectionFactory redisConnectionFactory;

    @Scheduled(cron = "0/20 * * * * ?")
    public void task() {
        if (redisConnectionFactory instanceof LettuceConnectionFactory) {
            LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) redisConnectionFactory;
            connectionFactory.validateConnection();
        }
    }

}

springboot2.x, redis 默认使用lettuce,会出现连接超时问题,讲配置文件application.yml中 spring.redis.lettuce.pool.min-idle 连接池最小空闲连接 设置为1,本地测试可以解决问题。

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(7)
1151004 y project 1578942802 5032291 bigbear668 1578978835
JavaScript
1
https://gitee.com/y_project/RuoYi-Vue.git
git@gitee.com:y_project/RuoYi-Vue.git
y_project
RuoYi-Vue
RuoYi-Vue

搜索帮助