1.导入依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

2.编写测试类:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringbootthymeleafApplication.class)
public class RedisTest {

    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void test(){
        redisTemplate.opsForValue().set("a","oasjdjasdajd");
        Object a = redisTemplate.opsForValue().get("a");
        System.out.println(a);

        User user=new User();
        user.setId(1);user.setName("aa");user.setAge(10);
        redisTemplate.opsForValue().set("user",user);

        User user1 =(User) redisTemplate.opsForValue().get("user");
        System.out.println(user1);



    }

 

 

 

 

 

 

posted on 2019-11-06 19:14  MyBeans  阅读(288)  评论(0编辑  收藏  举报