springboot连接redis连接池和sentinel

springboot连接redis连接池和sentinel

在配置文件中配置application.yml

ip: 192.168.0.110
spring:
  redis:
    password: redis123
    timeout: 2000
    lettuce:
      pool:
        max-active: 1000#连接池最大连接数(使用负值表示没有限制)
        max-idle: 10# 连接池中的最大空闲连接
        max-wait: -1连接池最大阻塞等待时间(使用负值表示没有限制)
        min-idle: 5# 连接池中的最小空闲连接
    cluster:
      nodes: ${ip}:6379,${ip}:6380,${ip}:6381
      max-redirects: 3# 获取失败 最大重定向次数
    sentinel:
      master: redis_master
      nodes: ${ip}:26379

---------或者application.properties

spring.redis.password=redis123
spring.redis.timeout=6000
# 获取失败 最大重定向次数
spring.redis.cluster.max-redirects=3
#spring.redis.cluster.nodes=192.168.0.110:6379,192.168.0.110:6380,192.168.0.110:6381
#连接池最大连接数(使用负值表示没有限制)
spring.redis.lettuce.pool.max-active=1000
# 连接池中的最大空闲连接
spring.redis.lettuce.pool.max-idle=10
# 连接池中的最小空闲连接
spring.redis.lettuce.pool.min-idle=5
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.lettuce.pool.max-wait=-1
spring.redis.sentinel.password=redis123
spring.redis.sentinel.master=redis_master
spring.redis.sentinel.nodes=192.168.0.110:6379,192.168.0.110:6380,192.168.0.110:6381

---------

加入spring.redis.lettuce.pool的依赖,不然报Caused by:
java.lang.NoClassDefFoundError:
org/apache/commons/pool2/impl/GenericObjectPoolConfig

 <dependency>
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-pool2</artifactId>
</dependency>

springboot2.4

redis-5.0.10

2020-12-20

原文链接:,转发请注明来源!