出现错误:Redis exception:Connection reset by peer

参考文献
redis 之 Connection reset by peer — blog.csdn.net
springboot链redis出现 java.io.IOException: 远程主机强迫关闭了一个现有的连接 — blog.csdn.net
nested exception is io.lettuce.core.RedisException: java.io.IOException: Connection reset by peer #1350 — github.com
解决 Error connection reset by peer — szthanatos.github.io
Ask questionscom.lambdaworks.redis.RedisException: java.io.IOException: Connection reset by peer when execute handler in thread Thread — gitmemory.com
readAddress(..) failed: Connection reset by peer #1403 — github.com
What does “connection reset by peer” mean? — stackoverflow.com
Connection reset by peer —- everything2.com
Lettuce/Lobby Chat room for the Lettuce Redis driver project — gitter.im
记录修复 Redis 的 Connection reset by peer报错 #38 — github.com
记一次Redis Lettuce连接池Connection Reset By Peer排查经历 — www.zhihengshi.com

2021-02-04 16:23:56 这个问题很头疼,我查看了上面说的一些信息(说什么的都有点),上面的最后一篇文献讲的是我最同意的。

报错信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Exception in thread "KafkaTaskThread-42" org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: java.io.IOException: Connection reset by peer
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:74)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:273)
at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.convertLettuceAccessException(LettuceStringCommands.java:799)
at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.get(LettuceStringCommands.java:68)
at org.springframework.data.redis.connection.DefaultedRedisConnection.get(DefaultedRedisConnection.java:266)
at org.springframework.data.redis.connection.DefaultStringRedisConnection.get(DefaultStringRedisConnection.java:404)
at org.springframework.data.redis.core.DefaultValueOperations$1.inRedis(DefaultValueOperations.java:57)
at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:60)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:228)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:188)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:96)
at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:53)
at com.decathlon.sfc.order.bff.core.mapping.rule.JdAddressRule.getAddress(JdAddressRule.java:215)
at com.decathlon.sfc.order.bff.core.mapping.rule.JdAddressRule.apply(JdAddressRule.java:158)
at com.decathlon.sfc.order.bff.core.entity.task.Task.executeMapping(Task.java:90)
at com.decathlon.sfc.order.bff.core.thread.KafkaTaskThread.bizFunc(KafkaTaskThread.java:106)
at com.decathlon.sfc.order.bff.core.thread.BaseTaskThread.run(BaseTaskThread.java:44)

解决方案

我的做法

把 yml 改了一下
在这里插入图片描述

1
2021-02-04 16:24:09 等待校验,暂时没问题(已经发布生产 3个小时了)

网上方案

如果你按照我的做法修改了 “application.yml timeout = 60000” 还不可以的话。

下面可以修改你的 Redis 服务端配置

  1. 修改前,我们先查看 Redis 配置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    # 查看当前连接数
    127.0.0.1:6379> info clients
    # Clients
    connected_clients:3
    client_recent_max_input_buffer:8
    client_recent_max_output_buffer:0
    blocked_clients:0
    tracking_clients:0
    clients_in_timeout_table:0
    # 查看超时
    127.0.0.1:6379> config get time*
    1) "timeout"
    2) "0"
    # 查看最大存活时间
    127.0.0.1:6379> config get tcp*
    1) "tcp-keepalive"
    2) "300"
    3) "tcp-backlog"
    4) "511"
    # 查看最大客户端数
    127.0.0.1:6379> config get maxc*
    1) "maxclients"
    2) "10000"
  1. 修改 Redis 配置(临时生效,重启 Redis 失效,想持久有效可修改配置文件)
    1
    2
    3
    4
    5
    6
    7
    8
    # 最大连接数 3W
    config set maxclients 30000

    # 超时时间 300 秒
    config set timeout 300

    # 最大存活时间 60 秒
    config set tcp-keepalive 60