Spring Boot 整合Redis集群
1. pom文件中引入Redis依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
2. 修改配置文件
application.yml
spring:
# Redis 缓存
redis:
cluster:
nodes:
- 10.7.12.23:7001
- 10.7.12.23:7002
- 10.7.12.23:7003
database: 0
jedis:
pool:
# 连接池最大连接数(使用负值表示没有限制)
max-active: 130
# 连接池中的最大空闲连接
max-idle: 30
# 连接池中的最小空闲连接
min-idle: 10
# 连接池最大阻塞等待时间(使用负值表示没有限制
max-wait: 3s
# 连接超时时间
timeout: 6s
或
application.properties
spring.redis.cluster.nodes=127.0.0.1:8881,127.0.0.1:8882,127.0.0.1:8883
spring.redis.database=0
spring.redis.jedis.pool.max-active=130
spring.redis.jedis.pool.max-idle=30
spring.redis.jedis.pool.min-idle=10
spring.redis.jedis.pool.max-wait=3s
spring.redis.timeout=6s
补充说明
使用lettuce连接池
spring:
# Redis 缓存
redis:
cluster:
nodes:
- 10.7.12.23:7001
- 10.7.12.23:7002
- 10.7.12.23:7003
database: 0
lettuce:
pool:
# 连接池最大连接数(使用负值表示没有限制)
max-active: 130
# 连接池中的最大空闲连接
max-idle: 30
# 连接池中的最小空闲连接
min-idle: 10
# 连接池最大阻塞等待时间(使用负值表示没有限制
max-wait: 3s
# 连接超时时间
timeout: 6s
使用哨兵
spring:
# Redis 缓存
redis:
##单机
# host: 127.0.0.1
# port: 6379
##
##集群
cluster:
nodes:
- 127.0.0.1:7000
- 127.0.0.1:7001
- 127.0.0.1:7002
##哨兵
sentinel:
master: mymaster
nodes:
- 127.0.0.1:7003
- 127.0.0.1:7004
- 127.0.0.1:7005
database: 0
jedis:
pool:
# 连接池最大连接数(使用负值表示没有限制)
max-active: 130
# 连接池中的最大空闲连接
max-idle: 30
# 连接池中的最小空闲连接
min-idle: 10
# 连接池最大阻塞等待时间(使用负值表示没有限制
max-wait: 3s
# 连接超时时间
timeout: 6s
还没有评论,来说两句吧...