2023-03-29 10:54:38.186 ERROR 9136 --- [ntainer#7-0-C-1] c.n.r.service.IntersectionQueryService : Exception in getIntersectionById() with cause = 'redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out' and exception = 'java.net.SocketTimeoutException: Read timed out; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out' org.springframework.data.redis.RedisConnectionFailureException: java.net.SocketTimeoutException: Read timed out; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:65) at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:42) 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.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:187) at org.springframework.data.redis.connection.jedis.JedisConnection.doWithJedis(JedisConnection.java:802)
2023-08-24 09:44:23.721 ERROR 92250 --- [ns-pool-evictor] redis.clients.jedis.JedisFactory : Error while validating pooled Jedis object. redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out at redis.clients.jedis.util.RedisInputStream.ensureFill(RedisInputStream.java:205) at redis.clients.jedis.util.RedisInputStream.readByte(RedisInputStream.java:43) at redis.clients.jedis.Protocol.process(Protocol.java:162) at redis.clients.jedis.Protocol.read(Protocol.java:227) at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:352) at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:270) at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:380) at redis.clients.jedis.JedisFactory.validateObject(JedisFactory.java:214) at org.apache.commons.pool2.impl.GenericObjectPool.evict(GenericObjectPool.java:745) at org.apache.commons.pool2.impl.BaseGenericObjectPool$Evictor.run(BaseGenericObjectPool.java:160)
- Redis未正常在运行,异常终止,或者启动失败
- 未正确在程序里配置连接ip端口参数,例如ip错误使用localhost,又不在一台机器上
- 检查程序服务于redis之间的网络是否联通,是否存在明显延迟
- 可以修改Spring redis配置参数,增加连接超时时间
- 检查服务器情况,确保内存和磁盘空间充足,检查已使用内存、剩余内存、已使用磁盘、剩余磁盘等
- 简单来说,你的服务对redis的使用频率,如果读写很高很频繁、数据内容很多,就提供比较好的服务器,或者搭建redis集群
- 也可以优化Spring redis配置参数,增加最大线程数、空闲线程数、连接超时时间等
- 如果比较大的集合对象在redis存取,会占用很多内存,高并发情况下,可能做不到及时响应,可以只缓存必要的字段属性
- 大量的key值,同时加到redis里面,又在一段时间后同时失效,造成瞬时压力过大,这要在业务上做一些随机失效时间
spring: redis: jedis: pool: min-idle: 10 max-idle: 300 # 改大了 max-wait: 30000 # 改大了 max-active: 200 # 改大了
core-app: image: june container_name: core volumes: - /etc/localtime:/etc/localtime depends_on: - postgresql - redis environment: - _JAVA_OPTIONS=-Xmx6G -Xms1G - SERVER_PORT=8181 - SPRING_PROFILES_ACTIVE=prod,api-docs,no-liquibase - SPRING_DATASOURCE_URL=jdbc:postgresql://postgresql:5432/core - SPRING_DATASOURCE_USERNAME=xxxx - SPRING_DATASOURCE_PASSWORD=xxxxxxx - SPRING_REDIS_HOST=redis - SPRING_REDIS_PASSWORD=xxxxxxxx - spring_redis_jedis_pool_maxIdle=300 # redis配置 - spring_redis_jedis_pool_maxWait=30000 - spring_redis_jedis_pool_maxActive=200 restart: on-failure