内容不详尽,仅供自己参考!!!
引入坐标
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>${spring-boot.version}</version>
</dependency>
配置yml
spring:
redis:
host: 192.168.233.129
测试类
@SpringBootTest(classes = RedisApplication.class)
@RunWith(SpringRunner.class)
public class RedisDemo01 {
@Resource
private RedisTemplate redisTemplate;
@Resource
StringRedisTemplate stringRedisTemplate;
@Test
public void test01(){
ValueOperations ops = redisTemplate.opsForValue();
Object name = ops.get("name");
System.out.println("name = " + name);
}
@Test
public void test02(){
ValueOperations ops = redisTemplate.opsForValue();
ops.set("name" , 10);
}
@Test
public void test03(){
String name = stringRedisTemplate.opsForValue().get("name");
System.out.println("name = " + name);
}
}