- 下载安装redis
下载地址
这里我们安装中间的Stable(5.0)这个是稳定版本
下载完盲安装
2. 在cmd命令找到redis安装目录输入:redis-server redis.windows.conf 即可运行成功。
- redis的缓存机制配置yml文件写法
## Redis 配置
## Redis数据库索引(默认为0)
redis:
database: 1
## Redis服务器地址
host: localhost
## Redis服务器连接端口
port: 6379
## Redis服务器连接密码(默认为空)
password:
lettuce:
pool:
## 连接池最大连接数(使用负值表示没有限制)
max-active: 8
## 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: 3
## 连接池中的最大空闲连接
max-idle: 8
## 连接池中的最小空闲连接
min-idle: 0
## 连接超时时间(毫秒)
timeout: 5000
4.Pom文件
<!--spring2.0集成redis所需common-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!-- redis依赖,2.0以上使用这个依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- 缓存依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
- 这里是用的springboot2.2.0版本,现在不知道需要不需要写RedisConfig等缓存配置文件,哪位大神看见给老弟回请教一下!
- 测试缓存机制 编写一个user实体类、一个service接口、还有一个serviceImp接口实现类、一个测试类
Service接口类
ServiceImp类
测试类
点击测试,注意测试类get方法中缓存,在获取这个对应的
最后感谢各位大佬施舍我知识,借鉴文章,我恬不知耻的抄到我自己博客,抄到手就是我自己的!