springboot——redis win7 下安装配置

一、redis win7 安装配置

详解:https://jingyan.baidu.com/album/86fae346e132363c49121aac.html?picindex=3

二、springboot demo

使用 redis spring cache实现缓存

(1)代码实现

1、依赖

<dependency><!-- redis依赖-->
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-data-redis</artifactId>
		    <version>1.5.7.RELEASE</version>
		</dependency>
		
		<dependency><!-- 缓存依赖 -->
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-cache</artifactId>
		</dependency>

2、配置

主类添加:开启缓存
@EnableCaching
spring.cache.type=redis
spring.cache.cache-names=dataCenter,datahub

# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=localhost
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=0
# 缓存过期时间
redis-timeout=10
业务service代码上添加
@Cacheable(value = "dataCenter", key = "#root.methodName + '_' + #root.methodName.concat(#id)")

猜你喜欢

转载自blog.csdn.net/qq_42683700/article/details/81135461