Spring BootがRedisクラスターを統合

1. pomファイルにRedis依存関係を導入する

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

2.構成ファイルを変更します

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

または

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

補足説明

レタス接続プールを使用する

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

歩哨を使用する

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件の元の記事を公開しました 143件のいいね 890,000回の閲覧

おすすめ

転載: blog.csdn.net/jeikerxiao/article/details/99590312