使用redis做缓存整合起来并不难,在整合的时候一定要将show sql打开,这样才能测试你写整合的redis缓存是否成功了。首先,你需要在官网下载一个redis,然后启动redis-server,默认端口是6379,启动后的界面如下:
redis在springboot的maven依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
在application.yml添加配置信息,其中cache_name是自定义的缓存名字,可以定义多个
spring:
redis:
##默认redis客户端连接为0 可修改
database: 0
host: 127.0.0.1
port: 6379
cache_name: XiChuanRedis
##password:
pool:
##连接池最大空闲连接
max-idle: 8
min-idle: 0
max-active: 8
max-wait: 1
timeout: 5000