首页
学习
活动
专区
圈层
工具
发布

SpringBoot集成Redis

目标:实现SpringBoot集成Redis

工具:IDEA--2020.1

学习目标:实现SpringBoot集成Redis

本次学习的工程下载链接放到文本最后面

添加相关依赖

代码语言:javascript
复制
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

在application.yml里面配置Redis的数据源

代码语言:javascript
复制
spring:
  redis:
    host: localhost
    port: 6379

在HelloController里面使用RedisTemplate实现Redis的操作

具体Redis操作见 https://www.xmaven.cn/index.php/archives/152/

代码语言:javascript
复制
@RestController
public class HelloController {
    @Autowired
    RedisTemplate<String,String> redisTemplate;

    @GetMapping("/hello")
    public String hello(){
        redisTemplate.opsForValue().set("key","value");
        return "Hello world";
    }
}

启动工程

代码语言:javascript
复制
访问 http://localhost:8080/hello
  1. 查看redis数据库

下载链接: springboot-redis.rar

下一篇
举报
领券