package com.reyun.saas.common.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

@Configuration
public class CustomRedisConfig {

    /**
     * 实时的redis集群地址
     */
    @Value("${realTime.redisCluster.nodes}")
    private String redisCluster;


    /**
     * 实时的redis集群
     * @return
     */
    @Bean(name = "realTimeJedisCluster")
    public JedisCluster jedisCluster(){
        Set<HostAndPort> nodes = new HashSet<>();

        String[] ipPorts = redisCluster.split(",");
        for (String ipPort : ipPorts) {
            String[] ipPortPair = ipPort.split(":");
            nodes.add(new HostAndPort(ipPortPair[0].trim(), Integer.valueOf(ipPortPair[1].trim())));
        }

        return new JedisCluster(nodes);
    }




}
