<commit_before>package cn.howardliu.gear.spring.boot.autoconfigure;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MapPropertySource;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;

import java.util.HashMap;
import java.util.Map;

import static cn.howardliu.gear.spring.boot.autoconfigure.RedisLettuceProperties.REDIS_LETTUCE_PREFIX;

/**
 * <br>created at 17-5-17
 *
 * @author liuxh
 * @version 1.0.0
 * @since 1.0.0
 */
@Configuration
@ConditionalOnClass({
        RedisClusterConfiguration.class,
        LettuceConnectionFactory.class,
        StringRedisTemplate.class,
        RedisCacheManager.class
})
@ConditionalOnProperty(prefix = REDIS_LETTUCE_PREFIX, name = "nodes")
@EnableConfigurationProperties(RedisLettuceProperties.class)
@AutoConfigureBefore(RedisAutoConfiguration.class)
public class RedisLettuceAutoConfiguration extends CachingConfigurerSupport {
    private static final Logger logger = LoggerFactory.getLogger(RedisLettuceAutoConfiguration.class);
    private RedisLettuceProperties properties;

    public RedisLettuceAutoConfiguration(RedisLettuceProperties properties) {
        this.properties = properties;
    }

    @Bean
    @ConditionalOnMissingBean
    public RedisClusterConfiguration clusterConfig() {
        Map<String, Object> map = new HashMap<>();
        map.put("spring.redis.cluster.nodes", this.properties.getNodes());
        map.put("spring.redis.cluster.max-redirects", this.properties.getMaxRedirects());
        return new RedisClusterConfiguration(new MapPropertySource("redis.properties", map));
    }

    @Bean(destroyMethod = "destroy")
    @ConditionalOnMissingBean
    public LettuceConnectionFactory lettuceConnectionFactory() {
        LettuceConnectionFactory factory = new LettuceConnectionFactory(clusterConfig());
        if (StringUtils.isNotBlank(this.properties.getPassword())) {
            factory.setPassword(this.properties.getPassword());
        }
        return factory;
    }

    @Bean
    @ConditionalOnMissingBean
    public StringRedisTemplate redisTemplate() {
        StringRedisTemplate redisTemplate = new StringRedisTemplate(lettuceConnectionFactory());
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return redisTemplate;
    }

    @Bean
    @ConditionalOnMissingBean
    @Override
    public RedisCacheManager cacheManager() {
        RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate());
        cacheManager.setLoadRemoteCachesOnStartup(this.properties.isLoadRemoteCachesOnStartup());
        cacheManager.setUsePrefix(this.properties.isUsePrefix());
        cacheManager.setDefaultExpiration(this.properties.getDefaultExpiration());
        return cacheManager;
    }

    @Bean
    @ConditionalOnMissingBean
    @Override
    public SimpleParamsKeyGenerator keyGenerator() {
        return new SimpleParamsKeyGenerator();
    }
}<commit_msg>add bean type is RedisTemplate<commit_after>package cn.howardliu.gear.spring.boot.autoconfigure;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MapPropertySource;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;

import java.util.HashMap;
import java.util.Map;

import static cn.howardliu.gear.spring.boot.autoconfigure.RedisLettuceProperties.REDIS_LETTUCE_PREFIX;

/**
 * <br>created at 17-5-17
 *
 * @author liuxh
 * @version 1.0.0
 * @since 1.0.0
 */
@Configuration
@ConditionalOnClass({
        RedisClusterConfiguration.class,
        LettuceConnectionFactory.class,
        StringRedisTemplate.class,
        RedisCacheManager.class
})
@ConditionalOnProperty(prefix = REDIS_LETTUCE_PREFIX, name = "nodes")
@EnableConfigurationProperties(RedisLettuceProperties.class)
@AutoConfigureBefore(RedisAutoConfiguration.class)
public class RedisLettuceAutoConfiguration extends CachingConfigurerSupport {
    private static final Logger logger = LoggerFactory.getLogger(RedisLettuceAutoConfiguration.class);
    private RedisLettuceProperties properties;

    public RedisLettuceAutoConfiguration(RedisLettuceProperties properties) {
        this.properties = properties;
    }

    @Bean
    @ConditionalOnMissingBean
    public RedisClusterConfiguration clusterConfig() {
        Map<String, Object> map = new HashMap<>();
        map.put("spring.redis.cluster.nodes", this.properties.getNodes());
        map.put("spring.redis.cluster.max-redirects", this.properties.getMaxRedirects());
        return new RedisClusterConfiguration(new MapPropertySource("redis.properties", map));
    }

    @Bean(destroyMethod = "destroy")
    @ConditionalOnMissingBean
    public LettuceConnectionFactory lettuceConnectionFactory() {
        LettuceConnectionFactory factory = new LettuceConnectionFactory(clusterConfig());
        if (StringUtils.isNotBlank(this.properties.getPassword())) {
            factory.setPassword(this.properties.getPassword());
        }
        return factory;
    }

    @Bean(name = "stringRedisTemplate")
    @ConditionalOnMissingBean
    public StringRedisTemplate stringRedisTemplate() {
        StringRedisTemplate redisTemplate = new StringRedisTemplate(lettuceConnectionFactory());
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return redisTemplate;
    }

    @Bean(name = "redisTemplate")
    @ConditionalOnMissingBean(name = "redisTemplate")
    public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(connectionFactory);
        return redisTemplate;
    }

    @Bean
    @ConditionalOnMissingBean
    @Override
    public RedisCacheManager cacheManager() {
        RedisCacheManager cacheManager = new RedisCacheManager(stringRedisTemplate());
        cacheManager.setLoadRemoteCachesOnStartup(this.properties.isLoadRemoteCachesOnStartup());
        cacheManager.setUsePrefix(this.properties.isUsePrefix());
        cacheManager.setDefaultExpiration(this.properties.getDefaultExpiration());
        return cacheManager;
    }

    @Bean
    @ConditionalOnMissingBean
    @Override
    public SimpleParamsKeyGenerator keyGenerator() {
        return new SimpleParamsKeyGenerator();
    }
}
{'fraction_non_alphanumeric': 0.08633765021584412, 'fraction_numerical': 0.0037335200093338, 'mean_word_length': 5.24326292789512, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4561830', 'n_tokens_mistral': 2302, 'n_tokens_neox': 2251, 'n_words': 340}