首頁 > 資料庫 > Redis > Unable to connect to Redis無法連結到Redis如何解決

Unable to connect to Redis無法連結到Redis如何解決

WBOY
發布: 2023-05-28 20:16:04
轉載
6892 人瀏覽過

專案場景:

提示:這裡簡述專案相關背景:

#在某個專案中的提交按鈕不好用

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
登入後複製

Unable to connect to Redis無法連結到Redis如何解決

##完整的專案報錯資訊:

#org.springframework.data.redis.RedisConnectionFailureException: 無法連線到 Redis;巢狀異常是 io.lettuce.core.RedisConnectionException:無法連接到 127.0.0.1/:6379

   位於 org.springframework.data.redis.connection.lettuce.LettConnectionConnectionConnection至 org.springframework.data.redis.connection。 :1092)
   在org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1065)
   在org.springameConnection 。 (RedisConnectionUtils.java:132)
    在org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:95)
  get 在org.springframework.dataConnection.redis.RedpConnection.redis.s. ) .java:82)
    在org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:211)
    在org.springframework.data.redis.core.RedisTemplate. java :184)
    在org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
    在org.springframework.data.redis.95)
    在org.springframework.data.redis.core.DefaultValueOperations. 53 )
    在 com.wuyue.travel.service.HotelService.add(HotelService.java:60)
    在 com.wuyue.travel.service.HotelService$$FastClassBySpringCGLIB577547.invoke($$)
    在org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    在org.springframework.aop.framework.CglibAopProxy$CglibxyInspijavaration. org.springframework.aop.framework.ReflectiveMethodInitation.proceed(ReflectiveMethodInitation.java:163)
    在org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWspringframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransactionTransactionAspecoo 。 Interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
   位於org.springframework.aop.framework.ReflectiveMethodInitation.proceed(ReflectiveMethodInitation.java:186)
  p攔截(CglibAopProxy.java:688)
    在com.wuyue.travel.service.HotelService$$EnhancerBySpringCGLIB$$af4f4c1f.add(<生成>)
    在com.$$yue.travel.Hotrolerue. add(HotelController.java:65)
    位於java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    位於java.base/java. Method.java:577)
    在org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
    在org.springframework.web.java:189)
    在org.springframework.web.methodquest.Indler. java:138)
   位於org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
cm.al. RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
    在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMapMap)5 mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
   位於org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)#cmul.web doService(DispatcherServlet.java:942)
   位於org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
   位於org.springframework.web.servlet.FrameServlet 908)
    在javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) 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)ApplicationFil .websocket.server.WsFilter.doFilter(WsFilter.java:53)
   位於org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)##> .doFilter(ApplicationFilterChain.java:166)
    在org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
  。 .doFilter(FilterChainProxy.java:334)
   位於org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)#FilPropring  位於設. (FilterChainProxy.java:334)
   在org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
  .java:334)
    在org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
   資料在Filorg.sp1. :334)
   位於org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
   設在org.springameFilwork.S.d. )
    在org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
    在org.springFilframework.security。 ##    在org.springframework.security。 ##    在org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
    在org.springframework.web.filter.OncePerRequestFilFilter.Pter( .springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    在org.springframework.security.web.contexttext .security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    在org.springframework.security.web.context.request.async.WebAsync:IntegrationFilter.5 .springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    在org.springframework.security.web.FilterChainProxy$V? .web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
   位於org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
  . (DelegatingFilterProxy.java:357)
   在org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
   在Apporg.apache.catalFil.java:270)
  )
    於org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    在org.springframework.web.filter .springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)#193)#193)#在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    在 org.springframework.web.filter.FormCont .filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   位於org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.javaApp:193)
 . (ApplicationFilterChain.java:166)
    在org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
   com )
    在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    在org.apache.catalina. .springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
   位於org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:位於107) . .ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   位於org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)## .java:199)
   位於org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
   位於org.apache.catalina.authenticator.AuthenticatorBase#invoke(AuthenticBase. ##    在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) .catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
   位於org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
1p  位於org.apache.coytt.http#1. .service(Http11Processor.java:408)
   位於org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
   位於org.proache.coyote.AbstractProtocol. )
    在org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
    在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcess.Base. )
    在java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    在java.base/java.util.concurrent.ThreadPoolExecutor$Worker8. )
   在org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   在java.base/java.lang.Thread.run(Thread.java:833)
原因:io.lettuce.core.RedisConnectionException:無法連接到127.0.0.1/:6379
    at io.lettuce.core.RedisConnectionException.create(RedisException.java:78)##在製.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
    在io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:234)##Red   在在Redio. . .java:204)
   位於org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:113)
  Optional.java:364)
   位於org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:113)
   位於org.springamework.data.Factors.nection.data.Factors.nection.data.Factors.nection.data.Factors.nection.data.Factors.nection.data.Factors.nection.data.Factors.nection. SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1085)
    ... 103 更多
引起:io.netty.channel.AbstractChannel$AnnotatedConnectException:連線被拒絕:沒有更多資訊:/127.0.0.1:6379
    在java.base/sun.nio.ch.Net.pollConnect(本機方法)
    在java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
    在java .基底/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)
   在io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327)#.java# 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

问题描述:

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

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

Unable to connect to 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检查页面,当然我还是没看出啥问题????

Unable to connect to Redis無法連結到Redis如何解決

解决方案:

提示:缺少Redis环境

Unable to connect to Redis無法連結到Redis如何解決

最后运行成功!

Unable to connect to Redis無法連結到Redis如何解決

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

Unable to connect to Redis無法連結到Redis如何解決

以上是Unable to connect to Redis無法連結到Redis如何解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:yisu.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板