错误如下:
2021-11-30 19:48:30.002 [taskScheduler-2] ERROR com.test.daq.utils.RedisUtils - org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16777216 byte(s) of direct memory (used: 503316480, max: 514850816)
原因:
spring-boot-starter-data-redis 默认使用了lettuce,lettuce使用 netty进行网络通信,lettuce 的bug导致netty堆外内存溢出,解决办法 改为使用jedis,具体操作如下:
解决:
<!-- nested exception is io.lettuce.core.RedisException: io.netty.util.internal.OutOfDirectMemoryError
lettuce有bug,高并发情况下会出现以上错误,使用jedis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>