记录下SpringBoot集成Redis的方式。
SpringBoot2.5.3 + Redis-x64-3.2.1
<!-- redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
redis: localhost: localhost port: 6379 password:
@RestController @RequestMapping("/redis") public class RedisController { @Autowired private StringRedisTemplate redisTemplate; @GetMapping(value = "/setVal") public void setVal(@RequestParam String name) { redisTemplate.opsForValue().set("name", name); } @GetMapping(value = "/getVal") public void getVal() { String name = redisTemplate.opsForValue().get("name"); System.out.println("name:" + name); } }