springboot整合redis
导依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
配置数据源在(.yml中)
spring: redis: host: 192.168.110.10 port: 6379
测试类
@Autowired private RedisTemplate redisTemplate; @Test public void testRedis(){ //redis存入数据 redisTemplate.opsForValue().set("hi","hello"); //redis去除数据 String str=(String) redisTemplate.opsForValue().get("hi"); System.out.println(str); MUser mUser= new MUser(); mUser.setId(1); mUser.setName("张三"); mUser.setUsername("你好呀"); mUser.setPassword("123456"); redisTemplate.opsForValue().set("user",mUser); MUser user = (MUser)redisTemplate.opsForValue().get("user"); System.out.println(user); }