Redisson+Springboot配置(哨兵模式)


Maven依赖


    3.12.5




    org.redisson
    redisson-spring-boot-starter
    ${redisson.version}


与SpringBoot版本对应

Springboot版本一般与Spring Data Redis版本对应

Spring Data Redis Redisson-spring-data
v.1.6.x redisson-spring-data-16
v.1.7.x redisson-spring-data-17
v.1.8.x redisson-spring-data-18
v.2.0.x redisson-spring-data-20
v.2.1.x redisson-spring-data-21
v.2.2.x redisson-spring-data-22
v.2.3.x redisson-spring-data-23
v.2.4.x redisson-spring-data-24
v.2.5.x redisson-spring-data-25
v.2.6.x redisson-spring-data-25
  • 进入redisson-spring-boot-starter
  • 定位redisson-spring-data查看版本

redisson-spring-data


配置方法

  • 独立redisson.yaml配置文件
  • 独立redisson.json配置文件
  • 直接配置在application.yaml

三种配置方法,因版本不同具体需要根据实际配置类,这里以3.12.5-sentinel哨兵举例

  • org.redisson.spring.starter.RedissonAutoConfiguration
  • org.redisson.spring.starter.RedissonProperties

redisson.yaml方式

application.yaml:

spring:
  redis:
    config: classpath:redisson.yaml

redisson.yaml:

sentinelServersConfig:
  sentinelAddresses:
  - "redis://192.168.1.241:8001"
  - "redis://192.168.1.242:8001"
  - "redis://192.168.1.243:8001"
  masterName: mymaster
  database: 2
  password: xxxxx
  slaveConnectionMinimumIdleSize: 10
  slaveConnectionPoolSize: 300
  masterConnectionMinimumIdleSize: 10
  masterConnectionPoolSize: 300
threads: 0
nettyThreads: 0
codec: ! {}
transportMode: "NIO"

redisson.json方式

application.yaml:

spring:
  redis:
    config: classpath:redisson.json

redisson.json:

{
  "sentinelServersConfig":{
    "sentinelAddresses": ["redis://192.168.1.241:26379","redis://192.168.1.241:36379","redis://192.168.1.241:46379"],
    "masterName": "mymaster",
    "database":10,
    "password":"admin"
  }
} 

application.yaml方式

spring:
  redis:
    database: 2
    sentinel:
      nodes:
      - "redis://192.168.1.241:8001"
      - "redis://192.168.1.242:8001"
      - "redis://192.168.1.243:8001"
      master: mymaster
    password: xxxxx

参考:

  • Redisson 使用手册-哨兵