Redis SpringBoot类怎么配置
作者:OpenWorld
时间:2023-04-25
浏览:2
Redis Assistant
Redis Assistant 是一款为Redis设计的高效可视化管理与监控工具,提供多种操作模式,高效处理服务器数据。日常使用里的持续防护和信息管理会更突出,适合把安全控制放进长期使用流程中的场景。
¥19
Windows/macOS/Linux
2026-08-22
importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importorg.springframework.data.redis.connection.RedisConnectionFactory;importorg.springframework.data.redis.core.RedisTemplate;importorg.springfra
本文目录
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* @ClassName : RedisConfig
* @Description : redis
* @Author : MJoeBoyae
* @Date: 2021-06-26 22:52
*/
@Configuration
public class RedisConfig {
// springboot启动后,自定义容器内部的redisTemplate对象,
@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
// 使用GenericJackson2JsonRedisSerializer序列化器,可以序列化和反序列化带泛型的数组
GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(stringRedisSerializer);
redisTemplate.setValueSerializer(genericJackson2JsonRedisSerializer);
redisTemplate.setHashKeySerializer(stringRedisSerializer);
redisTemplate.setHashValueSerializer(genericJackson2JsonRedisSerializer);
// 在设置好redisTemplate属性后,使用afterPropertiesSet()方法使得设置生效
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
作者最新文章
Yandex新闻入口 俄罗斯Yandex官网资讯直达
2026-11-21 10:10
QQ影音工具箱找不到转码选项怎么办
2026-11-20 17:52
漫蛙漫画弹幕怎么用?互动评论教程
2026-11-20 13:32
小橡皮一键直达入口 小橡皮AI网页版登录地址
2026-11-20 10:22
Poki免安装电脑网页版入口
2026-11-12 19:19
上一篇:
Java中什么是抽象工厂
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多

































