|
|
|
@@ -7,9 +7,13 @@ import org.springframework.cache.annotation.EnableCaching; |
|
|
|
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.lettuce.LettuceConnectionFactory; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; |
|
|
|
import org.springframework.data.redis.serializer.StringRedisSerializer; |
|
|
|
|
|
|
|
import java.io.Serializable; |
|
|
|
|
|
|
|
/** |
|
|
|
* redis配置 |
|
|
|
* |
|
|
|
@@ -39,4 +43,24 @@ public class RedisConfig extends CachingConfigurerSupport { |
|
|
|
template.afterPropertiesSet(); |
|
|
|
return template; |
|
|
|
} |
|
|
|
|
|
|
|
@Bean |
|
|
|
|
|
|
|
public RedisTemplate<String, Serializable> redisCacheTemplate(LettuceConnectionFactory redisConnectionFactory){ |
|
|
|
|
|
|
|
RedisTemplate<String,Serializable> template = new RedisTemplate<String,Serializable>(); |
|
|
|
|
|
|
|
template.setKeySerializer(new StringRedisSerializer()); |
|
|
|
|
|
|
|
template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); |
|
|
|
|
|
|
|
template.setHashKeySerializer(new StringRedisSerializer());// Hash key序列化 |
|
|
|
|
|
|
|
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());// Hash value序列化 |
|
|
|
|
|
|
|
template.setConnectionFactory(redisConnectionFactory); |
|
|
|
|
|
|
|
return template; |
|
|
|
|
|
|
|
} |
|
|
|
} |