All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lingdonge.redis.configuration.custom.RedisClusterAutoConfiguration Maven / Gradle / Ivy

package com.lingdonge.redis.configuration.custom;

import com.lingdonge.redis.RedisConfigUtil;
import com.lingdonge.redis.service.RedisClusterUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import redis.clients.jedis.JedisCluster;

/**
 * 集群环境配置
 */
@Configuration
@EnableConfigurationProperties(RedisProperties.class)
@Slf4j
public class RedisClusterAutoConfiguration {

    @Autowired
    private RedisProperties redisProperties;

    /**
     * Redis集群配置
     *
     * @return
     */
    @Bean
    public RedisClusterConfiguration redisClusterConfiguration() {
        return RedisConfigUtil.buildRedisClusterConfiguration(redisProperties);
    }

    /**
     * 配置集群的连接池
     *
     * @return
     */
    @Bean
    public JedisConnectionFactory jedisConnectionFactory() {
        return new JedisConnectionFactory(redisClusterConfiguration(), RedisConfigUtil.getJedisPoolConfig(redisProperties));
    }

    /**
     * Cluster集群配置
     *
     * @return
     */
    @Bean
    public JedisCluster jedisCluster() {
        return new JedisCluster(RedisConfigUtil.getClusterNodes(redisProperties), RedisConfigUtil.getJedisPoolGenericConfig(redisProperties));
    }

    /**
     * 构建RedisUtil的Bean实例
     *
     * @return
     * @throws Exception
     */
    @Bean
    public RedisClusterUtil redisClusterUtil() {
        log.info("<<<<<<<<<<<<<<< 加载 RedisClusterUtil 服务 >>>>>>>>>>>>>>>>>>");
        return new RedisClusterUtil(jedisCluster());
    }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy