lettuce icon indicating copy to clipboard operation
lettuce copied to clipboard

io.lettuce.core.RedisCommandTimeoutException: Command timed out after 1 second(s)

Open yuandongjian opened this issue 1 year ago • 3 comments

As long as the command is not executed for a period of time, there will be a timeout problem when the command is executed again. I'm pretty sure that Lettuce is causing the problem, because if I change to Jedis, it won't reappear. I see a lot of people who have the same problem and their solution is to switch to Jedis. How did this problem arise and how can it be solved?

Lettuce Version:6.1.5.RELEASE

@Bean
public StatefulRedisConnection<String, String> lettuceClient() {
        RedisURI uri = RedisURI.Builder.redis("127.0.0.1", 6379).withPassword("123456").withTimeout(Duration.ofSeconds(1)).build();
        RedisClient client = RedisClient.create(uri);
        return client.connect();
}

@Service
public class MyService {
    @Autowired
    private StatefulRedisConnection<String, String> connection;

    public void service() {
        String result = connection.sync().set("key", "value");
        String value = connection.sync().get("key");
    }
}

Caused by: io.lettuce.core.RedisCommandTimeoutException: Command timed out after 1 second(s)
    at io.lettuce.core.internal.ExceptionFactory.createTimeoutException(ExceptionFactory.java:53) ~[lettuce-core-6.1.5.RELEASE.jar!/:6.1.5.RELEASE]
    at io.lettuce.core.internal.Futures.awaitOrCancel(Futures.java:246) ~[lettuce-core-6.1.5.RELEASE.jar!/:6.1.5.RELEASE]
    at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:75) ~[lettuce-core-6.1.5.RELEASE.jar!/:6.1.5.RELEASE]
    at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80) ~[lettuce-core-6.1.5.RELEASE.jar!/:6.1.5.RELEASE]

yuandongjian avatar Aug 09 '22 07:08 yuandongjian

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal sample that reproduces the problem. Debug logs would help here, too.

mp911de avatar Nov 22 '22 10:11 mp911de

org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out after 5 second(s) at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:70) at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.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.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:268) at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.convertLettuceAccessException(LettuceStringCommands.java:799) at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.get(LettuceStringCommands.java:68) at org.springframework.data.redis.connection.DefaultedRedisConnection.get(DefaultedRedisConnection.java:253) at org.springframework.data.redis.connection.DefaultStringRedisConnection.get(DefaultStringRedisConnection.java:377) at org.springframework.data.redis.core.DefaultValueOperations$1.inRedis(DefaultValueOperations.java:57) at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:59) 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.AbstractOperations.execute(AbstractOperations.java:95) at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:53) at org.springframework.data.redis.core.DefaultBoundValueOperations.get(DefaultBoundValueOperations.java:50) at com.boke.common.autoconfigure.cache.SysCacheAspect.around(SysCacheAspect.java:90) at sun.reflect.GeneratedMethodAccessor1830.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at com.boke.sysserver.service.basic.BasicEnuDictionaryService$$EnhancerBySpringCGLIB$$7980f3c0.queryByCode() at com.boke.sysserver.service.order.OrderInputService.saveRTEESpecialMeal(OrderInputService.java:1149) at com.boke.sysserver.service.order.OrderInputService$$FastClassBySpringCGLIB$$adbffaa8.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684) at com.boke.sysserver.service.order.OrderInputService$$EnhancerBySpringCGLIB$$7da303e8.saveRTEESpecialMeal() at com.boke.sysserver.mqListener.RTEEListener.receiveQueueSpecialMeal(RTEEListener.java:33) at sun.reflect.GeneratedMethodAccessor2021.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:171) at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:120) at org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:114) at org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:77) at org.springframework.jms.config.TracingMessagingMessageListenerAdapter.onMessage(TracingJmsListenerEndpointRegistry.java:286) at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:736) at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:696) at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:674) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:318) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:257) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1189) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1179) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1076) at java.lang.Thread.run(Thread.java:748) Caused by: io.lettuce.core.RedisCommandTimeoutException: Command timed out after 5 second(s) at io.lettuce.core.ExceptionFactory.createTimeoutException(ExceptionFactory.java:51) at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:114) at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:69) at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80) at com.sun.proxy.$Proxy948.get(Unknown Source)

fanmuyong avatar Apr 23 '23 01:04 fanmuyong

@fanmuyong, could you try to provide a minimal sample as suggested by @mp911de ?

tishun avatar Apr 19 '24 11:04 tishun