linux部署redis连接超时 Redis command timed out
记一次项目部署redis错误,仅供参考
背景:linux上部署Java项目,使用redis
问题:访问Java接口,redis报错
"exception": "org.springframework.dao.QueryTimeoutException", "trace": "org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: Command timed out after 10 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:272) at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.convertLettuceAccessException(LettuceStringCommands.java:800) at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.get(LettuceStringCommands.java:70) at org.springframework.data.redis.connection.DefaultedRedisConnection.get(DefaultedRedisConnection.java:267) at org.springframework.data.redis.connection.DefaultStringRedisConnection.get(DefaultStringRedisConnection.java:406) at org.springframework.data.redis.core.DefaultValueOperations$1.inRedis(DefaultValueOperations.java:57) at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:60) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:222) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:189) at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:96) at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:53) at xyz.erupt.upms.service.EruptSessionService.get(EruptSessionService.java:56) at xyz.erupt.upms.service.EruptUserService.checkVerifyCode(EruptUserService.java:169) at xyz.erupt.upms.service.EruptUserService FastClassBySpringCGLIB 9f0f5a8d.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at xyz.erupt.upms.service.EruptUserService EnhancerBySpringCGLIB e980a164.checkVerifyCode(<generated>) at xyz.erupt.upms.controller.EruptUserController.login(EruptUserController.java:56) 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.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141) at org.springframework.web.servlet.mvc.method.annotation.
解决:redis.conf文件配置
bind 127.0.0.1 ::1 //添加注释,有的配置文件是 bin 127.0.0.1 ::1
bind 127.0.0.1 //添加注释,有的配置文件是 bin 127.0.0.1,表示绑定这一个ip,只有这个ip能访问,去掉表示不限制
protected-mode yes 改成 protected-mode no // 当开启后,禁止公网访问redis。它启用的条件有两个,第一是没有使用bind,第二是没有设置访问密码。
配置改好后在linux上重启redis: systemctl restart redis.service
