springboot集成主从redis

所需要的包


    org.springframework.boot
    spring-boot-starter-redis                    
    1.4.7.RELEASE

配置文件

spring:  
    redis:
        sentinel:
            master: mymaster #哨兵监听的redis server的名字
            nodes: 哨兵1:26379,哨兵2:26379
        password: 密码
        jedis:
          pool:
            max-idle: 100 #连接池中的最大空闲数
            min-idle: 1   #连接池中的最小空闲数
            max-active: 1000 #连接池最大连接数(使用负值表示没有限制)
            max-wait: -1 #连接池最大阻塞等待时间(使用负值表示没有限制)

测试

2020-02-07 15:01:04.029  INFO 14252 --- [nio-8082-exec-7] c.u.b.elevator.service.AuthService       : login success token = eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxNzc0ODc4OTAzOSIsImNyZWF0ZWQiOjE1ODEwNTg4NjQwMjksInJvbGVzIjoiUk9MRV9TVVBFUlZJU0UiLCJleHAiOjE1ODE2NjM2NjR9.uw1_LAk_2krGqOdlmmcxRutI2L01c6Rk1v4APu_U8JQJvZETdo5XWrBc40s584HwYinX-uZSyhOikFxqzWY6QQ
2020-02-07 15:01:05.170  WARN 14252 --- [xecutorLoop-1-8] io.lettuce.core.RedisClient              : Cannot connect Redis Sentinel at RedisURI [host='192.168.1.109', port=26379]: io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.1.109:26379
2020-02-07 15:01:05.272  WARN 14252 --- [xecutorLoop-1-9] io.lettuce.core.RedisClient              : Cannot connect Redis Sentinel at RedisURI [host='192.168.1.109', port=26379]: io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.1.109:26379
2020-02-07 15:01:05.283  INFO 14252 --- [ioEventLoop-4-9] i.l.core.protocol.ReconnectionHandler    : Reconnected to 192.168.1.90:6379
2020-02-07 15:01:05.384  INFO 14252 --- [oEventLoop-4-12] i.l.core.protocol.ReconnectionHandler    : Reconnected to 192.168.1.90:6379

 

你可能感兴趣的:(Java)