Background Description:
(1) A project, using redis to do storage, using the set nature of redis to do real-time statistics, but also store other statistics;
(2) the use of a lot of key, value set volume more;
(3) every day at zero time, back to clean up all the data in the current redis;
(4) exceptions occur after the zero point cleanup;
Exception site:
2018/03/13 00:00:20 OSS INFO [com.xxx.RedisDAO] – error
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202)
at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
at redis.clients.jedis.Protocol.process(Protocol.java:151)
at redis.clients.jedis.Protocol.read(Protocol.java:215)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
at redis.clients.jedis.Connection.getIntegerReply(Connection.java:265)
at redis.clients.jedis.Jedis.sadd(Jedis.java:1109)
at com.xxx.RedisDAO.setXXXKPI(RedisDAO.java:66)
at com.xxx.xxxRunnable.run(xxxRunnable.java:69)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.net.SocketInputStream.read(SocketInputStream.java:127)
at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:196)
… 9 more
2018/03/13 00:00:20 OSS INFO [com.xxx.RedisDAO] – error
java.lang.ClassCastException: java.lang.Long cannot be cast to [B
at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
at redis.clients.jedis.Jedis.set(Jedis.java:121)
at com.xxx.RedisDAO.setXXXXXKPI(RedisDAO.java:100)
at com.xxx.xxxRunnable.run(xxxRunnable.java:70)
at java.lang.Thread.run(Thread.java:745)
2018/03/13 00:00:20 OSS INFO [com.xxx.RedisDAO] – error
java.lang.ClassCastException: [B cannot be cast to java.lang.Long
at redis.clients.jedis.Connection.getIntegerReply(Connection.java:265)
at redis.clients.jedis.Jedis.sadd(Jedis.java:1109)
at com.xxx.RedisDAO.setXXXXXKPI(RedisDAO.java:167)
at com.xxx.xxxRunnable.run(xxxRunnable.java:71)
at java.lang.Thread.run(Thread.java:745)
(1) If there is a lot of data in the current redis, FLUSHDB operation, it takes a certain amount of time, blocking the response of redis, so the SocketTimeoutException appears first;
(2) After the connection exception, from the logs, then there is a ClassCastException, and the subsequent keep reporting this exception error;
In summary, checking the project code, we found several problems:
a. After an exception occurs in a redis connection operation, it should close the close, return the resource, and go to a redis connection again to use it. The program is written as follows: an exception is thrown, a log is recorded, and the redis connection is used again, and the exception is thrown all the time.
b. The connection pool is set too large, when restarting the project, the initialized connection plus the previously unreleased connection (directly kill the process, not released when closing), the instant link is too large;
c. Program design is not reasonable, because the data is displayed in real time statistics every day, you can set the key prefix different every day, the key expiration time, so that you do not have to FLUSHDB every day.
Similar Posts:
- How to Solve Jedis Error: java.lang.ClassCastException: java.lang.Long cannot be cast to [B
- [How to Solve] Caused by: java.net.SocketTimeoutException: connect timed out
- Redis uses connection pool to solve the problem of error reporting
- [Solved] SpringBoot Access Redis Error: java.lang.NoSuchMethodError: redis.clients.jedis.JedisPoolConfig.setMinEvictableIdleTime
- [Solved] Jedis:Exception in thread “main” java.lang.VerifyError: Bad type on operand stack
- Solution of JMeter pressure test “Java.Net.Socketexception: socket closed”
- Solution of JMeter pressure test “Java. Net. Socketexception: socket closed”
- [Solved] Redis has java.net.socketexception: permission denied: connect problem during stress test
- [Solved] increment Error: ERR value is not an integer or out of range
- [Solved] Jedis Error: NoSuchElementException: Timeout waiting for idle object