yaohx123 2019-03-01 09:37 采纳率: 50%
浏览 716
已结题

spring-data-redis使用cluster失败

错误信息如下:
Caused by: org.springframework.data.redis.RedisConnectionFailureException: Could not get a resource from the pool; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

代码如下:
RedisClusterConfig.class

@Configuration
public class RedisClusterConfig {
    @Bean
    RedisClusterConfiguration redisClusterConfiguration(){
        List<String> nodes = new ArrayList<>();
        nodes.add("192.168.145.141:7001");nodes.add("192.168.145.141:7002");nodes.add("192.168.145.141:7003");
        nodes.add("192.168.145.141:7004");nodes.add("192.168.145.141:7005");nodes.add("192.168.145.141:7006");
        RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(nodes);
        return redisClusterConfiguration;
    }
    @Bean("redisConnectionFactory")
    JedisConnectionFactory redisConnectionFactory(){
        JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(redisClusterConfiguration());
        return jedisConnectionFactory;
    }
    @Bean("redisCacheManager")
    public RedisCacheManager redisCacheManager() {
        return RedisCacheManager.create(redisConnectionFactory());
    }
}

DemoApplication.class


@SpringBootApplication
public class DemoApplication {
   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }
   @Bean
   public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
      return args -> {
         System.out.println("Let's inspect the beans provided by Spring Boot:");
         String[] beanNames = ctx.getBeanDefinitionNames();
         Arrays.sort(beanNames);
         for (String beanName : beanNames) {
            System.out.println(beanName);
         }
         RedisConnectionFactory redisConnectionFactory = (RedisConnectionFactory)ctx.getBean("redisConnectionFactory");
         RedisCacheManager redisCacheManager = (RedisCacheManager)ctx.getBean("redisCacheManager");
         Cache cache = redisCacheManager.getCache("abc");
         if(cache != null){
            cache.put("13",13);
            String a = cache.get("13").toString();
            System.out.println("a is " + a);
         }else {
            System.out.println("can not find cache");
         }
      };
   }
}

我调试发现配置有问题:
图片说明

pom信息如下:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>2.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>
    </dependencies>
  • 写回答

2条回答 默认 最新

  • Random17 2019-03-01 10:32
    关注
      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>2.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>
    

    这两依赖为啥需要单独引入?
    data-redis不要声明版本,parent-starter已经声明了,下面的jedis更不需要了,

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序