SpringBoot整合Redis
2020-02-06 08:19
423 查看
1、导入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
2、配置数据源
spring: redis: host: 192.168.79.10 port: 6379
3、写测试类
import com.offcn.entity.Student; import com.offcn.mapper.StudentMapper; import com.offcn.pojo.Stu; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.test.context.junit4.SpringRunner; import java.util.Date; import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest(classes = HelloApplication.class) public class SBTest { @Autowired private StudentMapper studentMapper; @Autowired private RedisTemplate redisTemplate; @Test public void test1(){ List<Stu> students = studentMapper.getStudents(); for (Stu student : students) { System.out.println(student); } } @Test public void testRedisTemplate(){ redisTemplate.opsForValue().set("hello","0708java"); String str = (String)redisTemplate.opsForValue().get("hello"); System.out.println(str); Student student = new Student("张桂军",1,"唱歌","本科","家里蹲",new Date()); redisTemplate.opsForValue().set("student",student); Student student1 = (Student)redisTemplate.opsForValue().get("student"); System.out.println(student1); } }
4、运行成功
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- spring-boot 整合redis
- springboot整合redis集群过程解析
- springboot整合spring-data-redis中的坑
- redis整合spring boot的hello world
- SpringBoot (十一) :数据访问springboot整合redis高性能缓存_一点课堂(多岸学院)
- Redis学习(三)——SpringBoot整合Redis-5.0.4集群
- Spring Boot2.0之 整合Redis事务
- Spring boot整合redis
- spring boot 整合redis 将代码记录以备以后使用
- springboot2.0 session存储到redis整合过程中踩倒的坑
- springboot+shiro+redis(集群redis版)整合教程
- Spring Boot+Shiro+Redis(redisson)整合时,采用内嵌tomcat启动错误原因分析
- java整合springboot+mybits+redis+rabbitmq的秒杀系统
- Springboot+redis 整合
- idea中使用springboot整合redis,并测试
- spring boot 整合redis
- SpringBoot(十二)-- 整合Redis
- redis5.0集群搭建实战,spring-boot整合redis集群测试
- springboot2.x+redis整合
- Spring Boot 整合 Redis 实现缓存操作