Spring Boot integra el clúster Redis

1. Introducir la dependencia de Redis en el archivo pom

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-redis</artifactId>
</dependency>

2. Modificar el archivo de configuración

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

O

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

Explicación suplementaria

Usar el grupo de conexión de lechuga

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

Use centinela

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
420 artículos originales publicados · 143 pulgares arriba · 890,000 vistas

Supongo que te gusta

Origin blog.csdn.net/jeikerxiao/article/details/99590312
Recomendado
Clasificación