@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisApplicationTests {
@Autowired
private RedisTemplate<Object, Object> template;
@Test
public void contextLoads() {
User user = new User();
user.setId("1");
user.setName("joe");
user.setPassword("123");
template.opsForValue().set(user.getId()+"",user);
//原本opsForValue()是只能操作字符串的.现在就可以操作对象了
User result = (User) template.opsForValue().get(user.getId()+"");
System.out.println(result.getId()+" "+result.getName());
}
}