package cn.huge.module.config;
|
|
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.time.Duration;
|
|
/**
|
* @title: MybatisPlus配置
|
* @description: MybatisPlus配置
|
* @company: hugeinfo
|
* @author: liyj
|
* @time: 2021-11-05 16:51:48
|
* @version: 1.0.0
|
*/
|
@Configuration
|
public class RedisConfig {
|
|
@Bean
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
// 创建RedisTemplate实例
|
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
// 设置链接工厂
|
template.setConnectionFactory(factory);
|
// 设置key和value的序列化方式
|
template.setKeySerializer(new StringRedisSerializer());
|
// 使用GenericJackson2JsonRedisSerializer,反序列化时保留泛型信息
|
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
template.afterPropertiesSet();
|
|
return template;
|
}
|
}
|
/**
|
* -------------------_ooOoo_-------------------
|
* ------------------o8888888o------------------
|
* ------------------88" . "88------------------
|
* ------------------(| -_- |)------------------
|
* ------------------O\ = /O------------------
|
* ---------------____/`---'\____---------------
|
* -------------.' \\| |// `.-------------
|
* ------------/ \\||| : |||// \------------
|
* -----------/ _||||| -:- |||||- \-----------
|
* -----------| | \\\ - /// | |-----------
|
* -----------| \_| ''\---/'' | |-----------
|
* -----------\ .-\__ `-` ___/-. /-----------
|
* ---------___`. .' /--.--\ `. . __----------
|
* ------."" '< `.___\_<|>_/___.' >'"".-------
|
* -----| | : `- \`.;`\ _ /`;.`/ - ` : | |-----
|
* -----\ \ `-. \_ __\ /__ _/ .-` / /-----
|
* ======`-.____`-.___\_____/___.-`____.-'======
|
* -------------------`=---='
|
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
* ---------佛祖保佑---hugeinfo---永无BUG----------
|
*/
|