目标:实现SpringBoot集成Redis
工具:IDEA–2020.1
学习目标:实现SpringBoot集成Redis
本次学习的工程下载链接放到文本最后面
添加相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
在application.yml里面配置Redis的数据源
spring:
redis:
host: localhost
port: 6379
在HelloController里面使用RedisTemplate实现Redis的操作
**具体Redis操作见 https://www.xmaven.cn/archives/java--redis-xue-xi-1 **
@RestController
public class HelloController {
@Autowired
RedisTemplate<String,String> redisTemplate;
@GetMapping("/hello")
public String hello(){
redisTemplate.opsForValue().set("key","value");
return "Hello world";
}
}
-
启动工程
访问 http://localhost:8080/hello
-
查看redis数据库
下载链接: springboot-redis.rar
评论区