|  | @@ -1,25 +1,70 @@
 | 
	
		
			
				|  |  |  package com.yonge.cooleshow.common.redis.config;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  |  import org.springframework.context.annotation.Bean;
 | 
	
		
			
				|  |  |  import org.springframework.context.annotation.Configuration;
 | 
	
		
			
				|  |  |  import org.springframework.data.redis.connection.RedisConnectionFactory;
 | 
	
		
			
				|  |  | +import org.springframework.data.redis.connection.RedisPassword;
 | 
	
		
			
				|  |  | +import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
 | 
	
		
			
				|  |  | +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
 | 
	
		
			
				|  |  |  import org.springframework.data.redis.core.RedisTemplate;
 | 
	
		
			
				|  |  | -import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
 | 
	
		
			
				|  |  |  import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
 | 
	
		
			
				|  |  |  import org.springframework.data.redis.serializer.StringRedisSerializer;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.io.Serializable;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  @Configuration
 | 
	
		
			
				|  |  |  public class RedisConfig {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	/*@Value("${spring.redis.host}")
 | 
	
		
			
				|  |  | +	private String host;
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  | +	@Value("${spring.redis.port}")
 | 
	
		
			
				|  |  | +	private int port;
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  | +	@Value("${spring.redis.password}")
 | 
	
		
			
				|  |  | +	private String password;
 | 
	
		
			
				|  |  | +	
 | 
	
		
			
				|  |  | +	@Value("${spring.redis.database}")
 | 
	
		
			
				|  |  | +	private int database;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Bean
 | 
	
		
			
				|  |  | +	public JedisConnectionFactory jedisConnectionFactory() {
 | 
	
		
			
				|  |  | +		RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
 | 
	
		
			
				|  |  | +		config.setHostName(host);
 | 
	
		
			
				|  |  | +		config.setPort(port);
 | 
	
		
			
				|  |  | +		if (StringUtils.isNotBlank(password)) {
 | 
	
		
			
				|  |  | +			config.setPassword(RedisPassword.of(password));
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		config.setDatabase(database);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		JedisConnectionFactory factory = new JedisConnectionFactory(config);
 | 
	
		
			
				|  |  | +		return factory;
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Bean
 | 
	
		
			
				|  |  | +	public RedisTemplate<String, Serializable> redisTemplate(JedisConnectionFactory jedisConnectionFactory) {
 | 
	
		
			
				|  |  | +		RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		StringRedisSerializer stringSerializer = new StringRedisSerializer();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		redisTemplate.setKeySerializer(stringSerializer);
 | 
	
		
			
				|  |  | +		redisTemplate.setHashKeySerializer(stringSerializer);
 | 
	
		
			
				|  |  | +		redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
 | 
	
		
			
				|  |  | +		redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer());
 | 
	
		
			
				|  |  | +		redisTemplate.setConnectionFactory(jedisConnectionFactory);
 | 
	
		
			
				|  |  | +		return redisTemplate;
 | 
	
		
			
				|  |  | +	}*/
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	@Bean
 | 
	
		
			
				|  |  |  	public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
 | 
	
		
			
				|  |  |  		// 定义redis模板
 | 
	
		
			
				|  |  |  		RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
 | 
	
		
			
				|  |  |  		redisTemplate.setConnectionFactory(redisConnectionFactory);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -		// 设置序列化器
 | 
	
		
			
				|  |  | +		// 创建序列号对象
 | 
	
		
			
				|  |  |  		StringRedisSerializer stringSerializer = new StringRedisSerializer();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  		redisTemplate.setKeySerializer(stringSerializer);
 | 
	
		
			
				|  |  |  		redisTemplate.setHashKeySerializer(stringSerializer);
 | 
	
		
			
				|  |  |  		redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
 |