> 데이터 베이스 > Redis > Redis에 연결할 수 없습니다. Redis에 연결할 수 없는 문제를 해결하는 방법

Redis에 연결할 수 없습니다. Redis에 연결할 수 없는 문제를 해결하는 방법

WBOY
풀어 주다: 2023-05-28 20:16:04
앞으로
6891명이 탐색했습니다.

프로젝트 시나리오:

팁: 프로젝트 관련 배경에 대한 간략한 설명은 다음과 같습니다.

특정 프로젝트의 제출 버튼은 사용하기 쉽지 않습니다

org.springframework.data.redis.RedisConnectionFailureException: 
Unable to connect to Redis; 
nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1/<unresolved>:6379
로그인 후 복사

Redis에 연결할 수 없습니다. Redis에 연결할 수 없는 문제를 해결하는 방법

完整的项目报错信息:

org.springframework.data.redis.RedisConnectionFailureException: Redis에 연결할 수 없습니다. 중첩된 예외는 io.lettuce.core.RedisConnectionException입니다. org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1092에서 127.0.0.1/:6379
에 연결할 수 없습니다. )
    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1065)
    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:865 )
    org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:340)
    org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:132)
    org에서 .springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:95)
    at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:82)
    at org.springframework.data.redis .core.RedisTemplate.execute(RedisTemplate.java:211)
    org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
    org.springframework.data.redis.core.AbstractOperations.execute에서 (AbstractOperations.java:95)
    org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:53)
    com.wuyue.travel.service.HotelService.add(HotelService.java:60)
com.wuyue.travel.service.HotelService$$FastClassBySpringCGLIB$$577547fe.invoke(<생성>)
    org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    org.springframework에 있습니다. aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.transaction.interceptor.Transaction AspectSupport.invokeWithinTransaction( TransactionAspectSupport.java:294)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org. springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
    com.wuyue.travel.service.HotelService$$EnhancerBySpringCGLIB$$af4f4c1f.add()
    com.wuyue.travel에서 .controller.admin.HotelController.add(HotelController.java:65)
    java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    java.base/java.lang.reflect.Method에서 .invoke(Method.java:577)
    org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java) :138)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMa pingHandlerAdapter .java : 895) org.springframework.web.servlet.method.annotation.requestmappingHandleInternal (requestMappingHandlerAdapter.java:800)
at org.springframework.web.shervc.bithodtor allwhervorthort Ermethodadapter .java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
    at org.springframework .web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
    javax.servlet.http.HttpServlet.service(HttpServlet.java :660)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    org.apache.tomcat.websocket.server에서 .WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166 )
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
   조직에서 .springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security .web.access.exceptiontranslationfilter.dofilter (ExceptionTranslationFilter.java:119)
org.springframework.security.web.filterchainproxy $ virtualfilterchain.dofilter (Filterchainproxy.java:334) atpret 필터 .doFilter(SessionManagementFilter.java:137)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter( AnonymousAuthenticationFilter.java :111)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java :170)
    조직에서 .springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
    at org.springframework.security.web .FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
    at org.springframework.security.web.FilterChainProxy$Vi rtualFilterChain .doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:10 7 )
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)에서
    org.springframework에서 .security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
    at org.springframework. 웹 .filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.FilterChainProxy.doFil terInternal(FilterChainProxy .java:215)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
    at org.springframework .web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil 터체인 .java:166)
    org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.apache에서 .catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
    org.springframework.web.filter.OncePerRequestFilter에서 .doFilter(OncePerRequestFilter.java:107)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.apache.catalina.core.ApplicationFilterChain에서 .internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    org.apache.catalina.core.ApplicationFilterChain에서 .doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    org.apache.catalina.valves.ErrorReportValve에서 .invoke(ErrorReportValve.java:92)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process에서 (AbstractProtocol.java:834)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java :49)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:833)
원인: io.lettuce .core.RedisConnectionException: io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
에서 127.0.0.1/:6379
     io.lettuce.core.RedisConnectionException.create(RedisConnectionException에 연결할 수 없습니다. .java:56)
    io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:234)
    io.lettuce.core.RedisClient.connect(RedisClient.java:204)
    org.springframework.data.redis에서 .connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:113)
    java.base/java.util.Optional.orElseGet(Optional.java:364)
    org.springframework.data.redis.connection에서. lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:113)
    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1085)
    ... 103개 더보기
원인: io. netty.channel.AbstractChannel$AnnotatedConnectException: 연결 거부됨: 추가 정보 없음: /127.0.0.1:6379
    java.base/sun.nio.ch.Net.pollConnect(Native Method)
    java.base/sun.nio에서. ch.Net.pollConnectNow(Net.java:672)
    java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)
    io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect( NioSocketChannel.java:327)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:636)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:583)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:500)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:462)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
... 1 more
Caused by: java.net.ConnectException: Connection refused: no further information
... 12 more

问题描述:

提示:这里描述项目中遇到的问题:

在某个项目中添加按钮一直显示执行出错

Redis에 연결할 수 없습니다. Redis에 연결할 수 없는 문제를 해결하는 방법

一开始想的是代码问题,于是翻看各层代码:

首先看页面:

<script>
    layui.use([&#39;form&#39;, &#39;upload&#39;, &#39;laydate&#39;] ,function(){

        var form = layui.form
            ,$ = layui.jquery
            ,layer = layui.layer
            ,upload = layui.upload
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: &#39;#date&#39;
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: &#39;#test1&#39;
            ,url: &#39;/uploadFile&#39;
            ,before: function(obj){
                //预读本地文件示例,不支持ie8
                obj.preview(function(index, file, result){
                    $(&#39;#demo1&#39;).attr(&#39;src&#39;, result); //图片链接(base64)
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg(&#39;上传失败&#39;);
                }
                //上传成功
                return layer.msg(&#39;上传成功&#39;);
            }
            ,error: function(){
                //演示失败状态,并实现重传
                var demoText = $(&#39;#demoText&#39;);
                demoText.html(&#39;<span >上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>&#39;);
                demoText.find(&#39;.demo-reload&#39;).on(&#39;click&#39;, function(){
                    uploadInst.upload();
                });
            }
        });

        //监听提交
        form.on(&#39;submit(setmyinfo)&#39;, function(obj){

            $.ajax({
                type: "POST",
                url: "/hotel",
                data: JSON.stringify(obj.field),
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                success: function(result) {
                    if(result.code == 0) {

                        //登入成功的提示
                        layer.msg(
                            result.message,{
                                icon: 1
                            });
                    } else {
                        layer.msg(result.message, {
                            icon: 5
                        });
                    }
                }
            });

        });

    });
</script>
로그인 후 복사

Controller层代码

	/**
	 * 增加
	 * @param hotel
	 */
	@ResponseBody
	@RequestMapping(method=RequestMethod.POST)
	public Result add(@RequestBody Hotel hotel){
		hotelService.add(hotel);
		return new Result(true,StatusCode.OK,"增加成功");
	}
로그인 후 복사

Dao层数据访问接口

public interface HotelDao extends JpaRepository<Hotel,String>,JpaSpecificationExecutor<Hotel>{

    List<Hotel> findByAddrLike(String addr);

}
로그인 후 복사

Service层代码

	/**
	 * 增加
	 * @param hotel
	 */
	public void add(Hotel hotel) {
		hotel.setId( idWorker.nextId()+"" );
		//取到缓存中的文件url
		String fileurl = (String) redisTemplate.opsForValue().get("fileurl");

		hotel.setImg("https://travel031.oss-cn-qingdao.aliyuncs.com/"+fileurl);
		hotelDao.save(hotel);
	}
로그인 후 복사

其实这一路看过来没发现啥问题,基本上是谁也不会觉得代码有问题

原因分析:

提示:Unable to connect to Redis

这意思是说无法连接到Redis

当时是看完代码觉得没问题又去F12检查页面,当然我还是没看出啥问题????

Redis에 연결할 수 없습니다. Redis에 연결할 수 없는 문제를 해결하는 방법

解决方案:

提示:缺少Redis环境

Redis에 연결할 수 없습니다. Redis에 연결할 수 없는 문제를 해결하는 방법

最后运行成功!

Redis에 연결할 수 없습니다. Redis에 연결할 수 없는 문제를 해결하는 방법

在管理员后台列表中也可以看到数据

Redis에 연결할 수 없습니다. Redis에 연결할 수 없는 문제를 해결하는 방법

위 내용은 Redis에 연결할 수 없습니다. Redis에 연결할 수 없는 문제를 해결하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:yisu.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿