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

org.zodiac.autoconfigure.redis.JedisClientAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.redis;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.zodiac.autoconfigure.redis.condition.ConditionalOnRedisEnabled;

@SpringBootConfiguration
@ConditionalOnRedisEnabled
@ConditionalOnClass(value = {org.zodiac.redis.RedisConfigInfo.class, redis.clients.jedis.Jedis.class})
@ConditionalOnProperty(name = org.zodiac.commons.constants.SystemPropertiesConstants.Zodiac.SPRING_REDIS_JEDIS_ENABLED, havingValue = "true")
public class JedisClientAutoConfiguration {

    /**
     * Resolving spring byName injection conflict.
     */
    public static final String BEAN_NAME_REDIS = "JedisClientAutoConfiguration.JedisService.Bean";

    private final RedisCacheCloudProperties redisCacheCloudProperties;
    private final JedisConnectionFactory jedisConnectionFactory;

    public JedisClientAutoConfiguration(RedisCacheCloudProperties redisCacheCloudProperties,
        ObjectProvider jedisConnectionFactoryProvider) {
        this.redisCacheCloudProperties = redisCacheCloudProperties;
        this.jedisConnectionFactory = jedisConnectionFactoryProvider.getIfAvailable();
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.redis.jedis.JedisClientFactoryBean jedisClientFactoryBean(
        ObjectProvider jedisClusterProvider,
        ObjectProvider jedisPoolProvider) {
        if (null != jedisConnectionFactory) {
            return new org.zodiac.redis.jedis.JedisClientFactoryBean(jedisConnectionFactory.getPoolConfig(), jedisClusterProvider.getIfAvailable(),
                jedisPoolProvider.getIfAvailable());
        }
        return new org.zodiac.redis.jedis.JedisClientFactoryBean(redisCacheCloudProperties, jedisClusterProvider.getIfAvailable(),
            jedisPoolProvider.getIfAvailable());
    }

    @Bean(BEAN_NAME_REDIS)
    @ConditionalOnMissingBean
    protected org.zodiac.redis.jedis.JedisService jedisService(org.zodiac.redis.jedis.JedisClientFactoryBean factory) throws Exception {
        return new org.zodiac.redis.jedis.JedisService(factory.getObject());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy