本文来写个例子说明springboot整合redis哨兵模式
环境搭建
maven引入
<!--redis依赖包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
yml文件配置
spring:
redis:
###################以下为redis单机模式配置###########################
#host: 192.168.31.6 # Redis服务器地址
#port: 6382 # Redis服务器连接端口
database: 0 # Redis数据库索引(默认为0)
password: 123456 # Redis服务器连接密码(默认为空)
timeout: 3000 # 连接超时时间(毫秒)
###################以下为redis哨兵增加的配置###########################
sentinel:
master: mymaster
nodes: 127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381
################ Redis的Java驱动包,使用lettuce连接池 ################
lettuce:
pool:
max-active: 200 # 连接池最大连接数(使用负值表示没有限制)
max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
max-idle: 10 # 连接池中的最大空闲连接 (默认为8)
min-idle: 0 # 连接池中的最小空闲连接
程序测试
结果验证
测试
redis6379
redis6380
redis6381