简单使用:SpringBoot整合Redis

1.导入依赖:


    org.springframework.boot
    spring-boot-starter-data-redis

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);



    }

 

 

 

 

 

 

你可能感兴趣的:(简单使用:SpringBoot整合Redis)