Unable to connect to 127.0.0.1/<unresolved>:6379

来源:3-6 实现外部缓存-Redis

weixin_慕瓜4554205

2023-06-08

老师我想请问一下为啥我在运行 RedisCacheTest.java的时候,他报错提示 Unable to connect to 127.0.0.1/:6379 呀?我启动了Redis,而且进行了ping操作,返回的是PONG;以及进行了set hello worldget hello操作,返回"world"。这个应该就代表是成功连接redis了吧?然后我有想,可能是Maven文件的问题,于是我clean了一下Maven文件,这时候控制台就显示:

[ERROR] [ERROR] Project 'com.imooc.pan:r-pan-mybatis-plus:1.0' is duplicated in the reactor @ 
[ERROR] Project 'com.imooc.pan:r-pan-mybatis-plus:1.0' is duplicated in the reactor -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DuplicateProjectException

Process finished with exit code 1

这个应该是哪里出问题了呢?是某一个pom.xml文件吗?谢谢老师!

=============================================================
Redis的配置:
这个是RedisCacheConfig.java文件

	@Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {

        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();

        redisTemplate.setConnectionFactory(redisConnectionFactory);
        redisTemplate.setKeySerializer(stringRedisSerializer);
        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
        redisTemplate.setHashKeySerializer(stringRedisSerializer);
        redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);

        return redisTemplate;
    }
    
	@Bean
    public CacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
        RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration
                .defaultCacheConfig()
                .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
                .serializeValuesWith(RedisSerializationContext.SerializationPair
                        .fromSerializer(new Jackson2JsonRedisSerializer<>(Object.class)));

        RedisCacheManager cacheManager = RedisCacheManager
                .builder(RedisCacheWriter.lockingRedisCacheWriter(redisConnectionFactory))
                .cacheDefaults(redisCacheConfiguration)
                .transactionAware()
                .build();

        log.info("The Redis cache manager is loaded successfully!");
        return cacheManager;
    }

这个是resources文件夹下的application.properties文件

spring.redis.database=1
spring.redis.host=127.0.0.1

这个是cache-redismodules下的pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>r-pan-cache</artifactId>
        <groupId>com.imooc.pan</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>r-pan-cache-redis</artifactId>

    <properties>
        <maven.compiler.source>18</maven.compiler.source>
        <maven.compiler.target>18</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.imooc.pan</groupId>
            <artifactId>r-pan-cache-core</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
    </dependencies>

</project>
写回答

2回答

RubinChu

2023-06-09

看代码是没啥问题,很可能是本地的环境哪里没有配置正确,检查一下redis的配置,完了手敲一下配置文件,之后mvn clean install一下  再运行单元测试试试

0
0

RubinChu

2023-06-08

Redis 配置咋配的,贴个图出来

0
1
weixin_慕瓜4554205
好的,老师。我更新了我最初的提出的问题,我有关redis的部分加上去了。
2023-06-09
共1条回复

SpringBoot+Vue3+Element Plus打造私人分布式存储系统

SpringBoot+Vue3+Element Plus 仿百度网盘实战

274 学习 · 346 问题

查看课程