修改redis序列化
This commit is contained in:
parent
db84d796c6
commit
52fa8239a7
|
|
@ -4,15 +4,13 @@ import org.springframework.data.redis.connection.RedisConnection;
|
|||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnection;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 自定义RedisTemplate,支持选库
|
||||
*
|
||||
* @author gxx
|
||||
*/
|
||||
@Component
|
||||
public class GridntRedisTemplate extends StringRedisTemplate {
|
||||
public class GridntRedisTemplate<K, V> extends StringRedisTemplate {
|
||||
|
||||
public GridntRedisTemplate(RedisConnectionFactory connectionFactory) {
|
||||
super.setConnectionFactory(connectionFactory);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.ruoyi.common.redis.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -18,7 +17,6 @@ import java.util.concurrent.TimeUnit;
|
|||
public class RedisService
|
||||
{
|
||||
@Autowired
|
||||
@Qualifier("gridntRedisTemplate")
|
||||
public RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue