1.引入redis依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.启动redis
3.实体类(一定要引入redis容器)
package com.example.demo.ceshi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class example01 {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@GetMapping("/Example01Set")
public String Example01Set() {
stringRedisTemplate.opsForValue().set("order", "123456");
return "success";
}
@GetMapping("/Example01Get")
public String Example01Get() {
return stringRedisTemplate.opsForValue().get("order");
}
}