1.30

测试目录结构如下

创建测试类SpringbootRedisApplicationTest

package com.itheima.springbootredis;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootRedisApplicationTests {
//注入redis
@Autowired
private RedisTemplate redisTemplate;

@Test
public void testSet() {
//存入数据
redisTemplate.boundValueOps("name").set("zhangsan");
}

@Test
public void testGet() {
//获取数据
Object name = redisTemplate.boundValueOps("name").get();
System.out.println(name);
}

}

posted @ 2024-02-28 23:54  奶油冰激凌  阅读(12)  评论(0)    收藏  举报