|
|
|
@ -3,12 +3,10 @@ package com.ruoyi.common.redis.configure;
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
|
|
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
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.connection.RedisStandaloneConfiguration;
|
|
|
|
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
|
|
|
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
|
|
|
|
|
|
|
@ -20,32 +18,16 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
|
|
|
@Configuration
|
|
|
|
|
@EnableCaching
|
|
|
|
|
public class RedisConfig extends CachingConfigurerSupport {
|
|
|
|
|
@Value("${spring.redis.host}")
|
|
|
|
|
private String host;
|
|
|
|
|
|
|
|
|
|
@Value("${spring.redis.port}")
|
|
|
|
|
private int port;
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public LettuceConnectionFactory lettuceConnectionFactory() {
|
|
|
|
|
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
|
|
|
|
|
redisStandaloneConfiguration.setHostName(host);
|
|
|
|
|
redisStandaloneConfiguration.setPort(port);
|
|
|
|
|
|
|
|
|
|
LettuceConnectionFactory factory = new LettuceConnectionFactory(redisStandaloneConfiguration);
|
|
|
|
|
// 关闭共享连接
|
|
|
|
|
factory.setShareNativeConnection(false);
|
|
|
|
|
return factory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public GridntRedisTemplate redisTemplate(LettuceConnectionFactory connectionFactory)
|
|
|
|
|
{
|
|
|
|
|
GridntRedisTemplate template = new GridntRedisTemplate(connectionFactory);
|
|
|
|
|
// 关闭共享连接
|
|
|
|
|
connectionFactory.setShareNativeConnection(false);
|
|
|
|
|
GridntRedisTemplate<Object, Object> template = new GridntRedisTemplate(connectionFactory);
|
|
|
|
|
template.setConnectionFactory(connectionFactory);
|
|
|
|
|
|
|
|
|
|
FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
|
|
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
|
|
|
|
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
|
|
|
|