@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class TestDemo {
//SpringBoot整合Redis
//1.获取RedisTemplate对象
@Autowired
private RedisTemplate redisTemplate;
//测试方法
@Test
public void getRedis(){
redisTemplate.opsForValue().set("Hello","ni hao");
String hello = (String)redisTemplate.opsForValue().get("Hello");
System.out.println(hello);
MyUser myUser = new MyUser();
myUser.setId(3);
myUser.setName("哈哈");
myUser.setPassword("123456");
myUser.setUsername("haha");
redisTemplate.opsForValue().set("myUser",myUser);
MyUser myUser1 = (MyUser)redisTemplate.opsForValue().get("myUser");
System.out.println(myUser1);
}
}