場景:
項目啟動過后 Redis 連接過一會就會斷開,報如下問題:
問題1:
2022-12-05 23:05:18.287 ERROR 10752 --- [sson-netty-1-11] o.redisson.client.handler.CommandsQueue :139 - Exception occured. Channel: [id: 0x7b1e0211, L:/xxx:60851 - R:/xxx:6379]
java.io.IOException: 遠(yuǎn)程主機強迫關(guān)閉了一個現(xiàn)有的連接。
at java.base/sun.nio.ch.SocketDispatcher.read0(Native Method)
at java.base/sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:233)
at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:223)
at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:358)
at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)
問題2:
Redis server response timeout (3000 ms) occured for command: (EVAL) with params: [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;..., 2, a:TestParamDtoOne(id=null, code=, userName=, email=), redisson_lock__channel:{a:TestParamDtoOne(id=null, code=, userName=, email=)}, 0, 30000, 033aee3e-7de4-415f-b627-69b3d7e17566:119] channel: [id: 0x9700eaf4, L:/xxx:60842 - R:/xxx:6379]
問題3:
nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out
一、解決
1、設(shè)置連接空閑超過 N(秒或毫秒)后關(guān)閉,0為禁用:redis.timeout: 60s(這里設(shè)置和tcp-keepalive的值一致)
2、設(shè)置 redis 服務(wù)端的配置文件 redis.conf 中 tcp-keepalive 的時間為60(單位秒)(TCP連接存活時間):tcp-keepalive 60
二、總結(jié)注意項
1、tcp-keepalive 超時時間默認(rèn)是300,應(yīng)該把這個存活時間改成小于或等于超時時間?redis.timeout文章來源:http://www.zghlxwxcb.cn/news/detail-649720.html
2、如果?tcp-keepalive?存活時間大于超時時間,存活時間還沒有結(jié)束(連接還沒關(guān)閉)就又創(chuàng)建新的連接,創(chuàng)建的連接多了就會遠(yuǎn)程主機強迫關(guān)閉現(xiàn)有連接文章來源地址http://www.zghlxwxcb.cn/news/detail-649720.html
到了這里,關(guān)于SpringBoot整合Redis:java.io.IOException: 遠(yuǎn)程主機強迫關(guān)閉了一個現(xiàn)有的連接?;蛘呖刂婆_報連接超時異常的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!