SpringBoot中使用Redis保存对象

本文介绍了如何在SpringBoot应用中集成Redis,并演示了如何配置RedisTemplate以存储和读取Employee对象,同时还提供了测试用例展示操作过程。
摘要由CSDN通过智能技术生成

1、引入依赖

org.springframework.boot spring-boot-starter-data-redis 1234 2、配置主机

spring.redis.host=192.168.124.15
1
3、查看源码
在这里插入图片描述

4、配置类

@Configuration
public class MyRedisConfig {
@Bean
public RedisTemplate<Object, Employee> empRedisTemplate(RedisConnectionFactory redisConnectionFactory)
throws UnknownHostException {
RedisTemplate<Object, Employee> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer<>(Employee.class);
template.setDefaultSerializer(serializer);
return template;
}
}
123456789101112
5、测试

@Autowired
RedisTemplate redisTemplate;
@Autowired
StringRedis

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值