refactor: 代码优化
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package com.youlai.system.config;
|
||||
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
@@ -13,22 +10,21 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
* Redis 配置
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class})
|
||||
public class RedisConfig {
|
||||
|
||||
/**
|
||||
* RedisTemplate 序列化配置
|
||||
* RedisTemplate 自定义序列化配置
|
||||
* <p>
|
||||
* 默认 JdkSerializationRedisSerializer,修改为 JSON 序列化
|
||||
*
|
||||
* @param lettuceConnectionFactory
|
||||
* @param redisConnectionFactory
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory lettuceConnectionFactory) {
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
|
||||
redisTemplate.setKeySerializer(RedisSerializer.string());
|
||||
redisTemplate.setValueSerializer(RedisSerializer.json());
|
||||
|
||||
Reference in New Issue
Block a user