java redis 超时_java - Redis忙时读取超时异常 - 堆栈内存溢出

我有一个用于事务数据获取并设置为Redis缓存的Spring Boot应用程序。 该应用程序每天的交易量为1000万。 我们的redis实例具有默认配置,并且没有哨兵,并且集群配置已禁用。 日常事务正在按预期方式进行和从redis获取。 我也有一个简单的rest控制器,用于删除数据并在持久化数据后重做。 当我在运行时调用此api时出现读取超时异常。 我正在使用jedis客户端连接到Redis。

我的redis配置类就像;

public class RedisConfiguration {

@Autowired

Environment environment;

@Bean

public RedisTemplate redisTemplate() {

RedisTemplate template = new RedisTemplate<>();

template.setConnectionFactory(jedisConnectionFactory());

return template;

}

@Bean

JedisConnectionFactory jedisConnectionFactory() {

String host = environment.getProperty("redis.host");

String portStr = environment.getProperty("redis.port");

int port=6379;

if(portStr!=null) {

port=Integer.valueOf(portStr);

}

String passwordStr = environment.getProperty("redis.password");

RedisPassword password = RedisPassword.of(passwordStr);

RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(host,port);

redisStandaloneConfiguration.setPassword(password);

return new JedisConnectionFactory(redisStandaloneConfiguration);

}

}

当我调用以下代码行时发生异常;

public void lastSixMonthAmountCacheScheduler() {

cacheRepository.deleteAll();

}

我正在使用默认的连接池配置。 在属性中只有redis连接主机端口用户名和密码信息。 当我调用上述方法时,出现以下错误;

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:67)

at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.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.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:181)

at org.springframework.data.redis.connection.jedis.JedisKeyCommands.keys(JedisKeyCommands.java:143)

at org.springframework.data.redis.connection.DefaultedRedisConnection.keys(DefaultedRedisConnection.java:75)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.springframework.data.redis.core.CloseSuppressingInvocationHandler.invoke(CloseSuppressingInvocationHandler.java:61)

at com.sun.proxy.$Proxy423.keys(Unknown Source)

at org.springframework.data.redis.core.IndexWriter.removeAllIndexes(IndexWriter.java:150)

at org.springframework.data.redis.core.RedisKeyValueAdapter.lambda$deleteAllOf$5(RedisKeyValueAdapter.java:392)

at org.springframework.data.redis.core.RedisKeyValueAdapter.dt_access$925(RedisKeyValueAdapter.java)

at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)

at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)

at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:171)

at org.springframework.data.redis.core.RedisKeyValueAdapter.deleteAllOf(RedisKeyValueAdapter.java:389)

at org.springframework.data.keyvalue.core.KeyValueTemplate.lambda$delete$4(KeyValueTemplate.java:279)

at org.springframework.data.keyvalue.core.KeyValueTemplate.dt_access$605(KeyValueTemplate.java)

at org.springframework.data.keyvalue.core.KeyValueTemplate.execute(KeyValueTemplate.java:343)

at org.springframework.data.keyvalue.core.KeyValueTemplate.delete(KeyValueTemplate.java:277)

at org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository.deleteAll(SimpleKeyValueRepository.java:203)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:377)

at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)

at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:629)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:593)

at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)

at com.sun.proxy.$Proxy174.deleteAll(Unknown Source)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)

at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)

at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)

at com.sun.proxy.$Proxy174.deleteAll(Unknown Source)

at com.ykb.frd.fraudservice.service.LastSixMonthAmountHabitCacheScheduler.lastSixMonthAmountCacheScheduler(LastSixMonthAmountHabitCacheScheduler.java:35)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)

at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)

at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at java.lang.Thread.run(Thread.java:748)

Caused by: 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.getBinaryMultiBulkReply(Connection.java:276)

at redis.clients.jedis.BinaryJedis.keys(BinaryJedis.java:357)

at org.springframework.data.redis.connection.jedis.JedisKeyCommands.keys(JedisKeyCommands.java:141)

... 64 common frames omitted

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)

... 71 common frames omitted

我的redis配置类中是否有任何问题,并且在负载默认redis连接池下无法正常工作?


版权声明:本文为weixin_42439576原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。