redis拒绝连接
# 具体遇到的问题
我linux的redis打开了,但是还是没有办法连接到
# 报错信息的截图
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: /127.0.0.1:6379
Caused by: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[?:1.8.0_221]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[?:1.8.0_221]
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:688) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
... 1 more
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
server.port = 8083 spring.datasource.name=imooc_mall_local_datasource spring.datasource.url=jdbc:mysql://127.0.0.1:3306/imooc_mall_local?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSl=false&serverTimezone=Asia/Shanghai spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.username=root spring.datasource.password=19990116 mybatis.mapper-locations=classpath:mappers/*.xml spring.redis.host = 127.0.0.1 spring.redis.port = 6379 spring.redis.password = 19990116a #上传文件的路径,根据部署情况,自行修改 file.upload.dir = C:/licheng/intellij IDEA/imooc-mall2-prepare-static/package com.imooc.mall.config; import java.time.Duration; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheConfiguration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.cache.RedisCacheWriter; import org.springframework.data.redis.connection.RedisConnectionFactory; /** * 描述: 缓存的配置类 */ @Configuration @EnableCaching public class CachingConfig { @Bean public RedisCacheManager redisCacheManager(RedisConnectionFactory connectionFactory) { RedisCacheWriter redisCacheWriter = RedisCacheWriter .lockingRedisCacheWriter(connectionFactory); RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig(); cacheConfiguration = cacheConfiguration.entryTtl(Duration.ofSeconds(30)); RedisCacheManager redisCacheManager = new RedisCacheManager(redisCacheWriter, cacheConfiguration); return redisCacheManager; } }package com.imooc.mall.service.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.imooc.mall.common.ApiRestResponse; import com.imooc.mall.exception.ImoocMallException; import com.imooc.mall.exception.ImoocMallExceptionEnum; import com.imooc.mall.model.dao.CategoryMapper; import com.imooc.mall.model.pojo.Category; import com.imooc.mall.model.request.AddCategoryReq; import com.imooc.mall.service.CategoryService; import com.imooc.mall.vo.CategoryVo; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.List; @Service public class CategoryServiceImpl implements CategoryService { @Autowired CategoryMapper categoryMapper; @Override public void add(AddCategoryReq addCategoryReq) { Category category = new Category(); BeanUtils.copyProperties(addCategoryReq, category); Category categoryOld = categoryMapper.selectByName(addCategoryReq.getName()); if (categoryOld != null) { throw new ImoocMallException(ImoocMallExceptionEnum.NAME_EXISTED); } int count = categoryMapper.insertSelective(category); if (count == 0) { throw new ImoocMallException(ImoocMallExceptionEnum.CREATE_FAILED); } } @Override public void update(Category updateCategory) { if (updateCategory.getName() != null) { Category categoryOld = categoryMapper.selectByName(updateCategory.getName()); if (categoryOld != null && !categoryOld.getId().equals(updateCategory.getId())) { throw new ImoocMallException(ImoocMallExceptionEnum.NAME_EXISTED); } } int count = categoryMapper.updateByPrimaryKeySelective(updateCategory); if (count == 0) { throw new ImoocMallException(ImoocMallExceptionEnum.UPDATE_FAILED); } } @Override public void delete(Integer id) { Category categoryOld = categoryMapper.selectByPrimaryKey(id); //找不到记录,无法删除,删除失败。 if (categoryOld == null) { throw new ImoocMallException(ImoocMallExceptionEnum.DELETE_FAILED); } int count = categoryMapper.deleteByPrimaryKey(id); if (count == 0) { throw new ImoocMallException(ImoocMallExceptionEnum.DELETE_FAILED); } } @Override public PageInfo listForAdmin(Integer pageNum, Integer pageSize) { PageHelper.startPage(pageNum, pageSize, "type, order_num"); List<Category> categoryList = categoryMapper.selectList(); PageInfo pageInfo = new PageInfo(categoryList); return pageInfo; } @Override @Cacheable(value = "listCategoryForCustomer") public List<CategoryVo> listCategoryForCustomer(Integer parentId){ ArrayList<CategoryVo> categoryVoArrayList = new ArrayList<>(); recursivelyFindCategories(categoryVoArrayList, parentId); System.out.println("categoryVoList:" + categoryVoArrayList); return categoryVoArrayList; } private void recursivelyFindCategories(List<CategoryVo> categoryVoList, Integer parentId) { List<Category> categoryList = categoryMapper.selectCategoriesByParentId(parentId); if(!CollectionUtils.isEmpty(categoryList)){ for (int i = 0; i < categoryList.size(); i++) { Category category = categoryList.get(i); CategoryVo categoryVO = new CategoryVo(); BeanUtils.copyProperties(category, categoryVO); categoryVoList.add(categoryVO); recursivelyFindCategories(categoryVO.getChildCategory(), categoryVO.getId()); } } } }
正在回答
同学你好,
1、建议同学检查一下ip和端口号是否正确。
2、建议同学在电脑上安装redis,连接本地redis试试。
- 参与学习 人
- 提交作业 9401 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星