|
|
@@ -1,26 +1,16 @@
|
|
|
package com.fs.framework.config;
|
|
|
|
|
|
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
|
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
|
-import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
|
|
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.data.redis.cache.RedisCacheConfiguration;
|
|
|
-import org.springframework.data.redis.cache.RedisCacheManager;
|
|
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
|
|
-import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
|
|
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
|
|
-import org.springframework.data.redis.serializer.RedisSerializationContext;
|
|
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.time.Duration;
|
|
|
|
|
|
/**
|
|
|
* redis配置
|
|
|
@@ -54,11 +44,6 @@ public class RedisConfig extends CachingConfigurerSupport
|
|
|
|
|
|
FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
|
|
|
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
|
|
- mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
|
|
- serializer.setObjectMapper(mapper);
|
|
|
-
|
|
|
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
|
|
template.setKeySerializer(new StringRedisSerializer());
|
|
|
template.setValueSerializer(serializer);
|
|
|
@@ -72,83 +57,77 @@ public class RedisConfig extends CachingConfigurerSupport
|
|
|
}
|
|
|
|
|
|
@Bean
|
|
|
- public RedisTemplate<String, Boolean> redisTemplateForBoolean(RedisConnectionFactory connectionFactory) {
|
|
|
- RedisTemplate<String, Boolean> template = new RedisTemplate<>();
|
|
|
+ public RedisTemplate<String, Integer> redisTemplateForInteger(RedisConnectionFactory connectionFactory) {
|
|
|
+ RedisTemplate<String, Integer> template = new RedisTemplate<>();
|
|
|
template.setConnectionFactory(connectionFactory);
|
|
|
|
|
|
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
|
|
template.setKeySerializer(new StringRedisSerializer());
|
|
|
- template.setValueSerializer(new GenericToStringSerializer<>(Boolean.class));
|
|
|
+
|
|
|
+ // 使用GenericToStringSerializer保证BigDecimal精度不丢失
|
|
|
+ template.setValueSerializer(new GenericToStringSerializer<>(Integer.class));
|
|
|
|
|
|
// Hash的key也采用StringRedisSerializer的序列化方式
|
|
|
template.setHashKeySerializer(new StringRedisSerializer());
|
|
|
- template.setHashValueSerializer(new GenericToStringSerializer<>(Boolean.class));
|
|
|
+ template.setHashValueSerializer(new GenericToStringSerializer<>(Integer.class));
|
|
|
|
|
|
template.afterPropertiesSet();
|
|
|
return template;
|
|
|
}
|
|
|
@Bean
|
|
|
- public RedisTemplate<String, BigDecimal> redisTemplateForBigDecimal(RedisConnectionFactory connectionFactory) {
|
|
|
- RedisTemplate<String, BigDecimal> template = new RedisTemplate<>();
|
|
|
+ public RedisTemplate<String, Boolean> redisTemplateForBoolean(RedisConnectionFactory connectionFactory) {
|
|
|
+ RedisTemplate<String, Boolean> template = new RedisTemplate<>();
|
|
|
template.setConnectionFactory(connectionFactory);
|
|
|
|
|
|
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
|
|
template.setKeySerializer(new StringRedisSerializer());
|
|
|
-
|
|
|
- // 使用GenericToStringSerializer保证BigDecimal精度不丢失
|
|
|
- template.setValueSerializer(new GenericToStringSerializer<>(BigDecimal.class));
|
|
|
+ template.setValueSerializer(new GenericToStringSerializer<>(Boolean.class));
|
|
|
|
|
|
// Hash的key也采用StringRedisSerializer的序列化方式
|
|
|
template.setHashKeySerializer(new StringRedisSerializer());
|
|
|
- template.setHashValueSerializer(new GenericToStringSerializer<>(BigDecimal.class));
|
|
|
+ template.setHashValueSerializer(new GenericToStringSerializer<>(Boolean.class));
|
|
|
|
|
|
template.afterPropertiesSet();
|
|
|
return template;
|
|
|
}
|
|
|
|
|
|
@Bean
|
|
|
- public RedisTemplate<String, Integer> redisTemplateForInteger(RedisConnectionFactory connectionFactory) {
|
|
|
- RedisTemplate<String, Integer> template = new RedisTemplate<>();
|
|
|
+ @SuppressWarnings(value = { "unchecked", "rawtypes" })
|
|
|
+ public RedisTemplate<String, Object> redisTemplateForObject(RedisConnectionFactory connectionFactory) {
|
|
|
+ RedisTemplate<String, Object> template = new RedisTemplate<>();
|
|
|
template.setConnectionFactory(connectionFactory);
|
|
|
|
|
|
+ FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
|
|
|
+
|
|
|
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
|
|
template.setKeySerializer(new StringRedisSerializer());
|
|
|
-
|
|
|
- // 使用GenericToStringSerializer保证BigDecimal精度不丢失
|
|
|
- template.setValueSerializer(new GenericToStringSerializer<>(Integer.class));
|
|
|
+ template.setValueSerializer(serializer);
|
|
|
|
|
|
// Hash的key也采用StringRedisSerializer的序列化方式
|
|
|
template.setHashKeySerializer(new StringRedisSerializer());
|
|
|
- template.setHashValueSerializer(new GenericToStringSerializer<>(Integer.class));
|
|
|
+ template.setHashValueSerializer(serializer);
|
|
|
|
|
|
template.afterPropertiesSet();
|
|
|
return template;
|
|
|
}
|
|
|
@Bean
|
|
|
- @SuppressWarnings(value = { "unchecked", "rawtypes" })
|
|
|
- public RedisTemplate<String, Object> redisTemplateForObject(RedisConnectionFactory connectionFactory) {
|
|
|
- RedisTemplate<String, Object> template = new RedisTemplate<>();
|
|
|
+ public RedisTemplate<String, BigDecimal> redisTemplateForBigDecimal(RedisConnectionFactory connectionFactory) {
|
|
|
+ RedisTemplate<String, BigDecimal> template = new RedisTemplate<>();
|
|
|
template.setConnectionFactory(connectionFactory);
|
|
|
|
|
|
- FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
|
|
|
-
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
|
|
- mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
|
|
- serializer.setObjectMapper(mapper);
|
|
|
-
|
|
|
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
|
|
template.setKeySerializer(new StringRedisSerializer());
|
|
|
- template.setValueSerializer(serializer);
|
|
|
+
|
|
|
+ // 使用GenericToStringSerializer保证BigDecimal精度不丢失
|
|
|
+ template.setValueSerializer(new GenericToStringSerializer<>(BigDecimal.class));
|
|
|
|
|
|
// Hash的key也采用StringRedisSerializer的序列化方式
|
|
|
template.setHashKeySerializer(new StringRedisSerializer());
|
|
|
- template.setHashValueSerializer(serializer);
|
|
|
+ template.setHashValueSerializer(new GenericToStringSerializer<>(BigDecimal.class));
|
|
|
|
|
|
template.afterPropertiesSet();
|
|
|
return template;
|
|
|
}
|
|
|
-
|
|
|
@Bean
|
|
|
public DefaultRedisScript<Long> limitScript()
|
|
|
{
|