redis的springboot配置

1.redis一主一从模式在springboot程序的application.yml里面配置

1.1 Lettuce作为Redis客户端

spring:
  redis:
    host: localhost
    port: 6379
    password:  # 如果有密码,填写密码信息
    lettuce:
      pool:
        max-active: 8
        max-idle: 8
        min-idle: 0
        max-wait: -1ms
  # Redis从节点配置
  # 配置主从关系,用于读写分离
  redis-slave:
    host: localhost
    port: 6380

1.2 Jedis作为客户端

spring:
  redis:
    host: localhost
    port: 6379
    password:  # 如果有密码,填写密码信息
    jedis:
      pool:
        max-active: 8
        max-idle: 8
        min-idle: 0
        max-wait: -1ms
  # Redis从节点配置
  # 配置主从关系,用于读写分离
  redis-slave:
    host: localhost
    port: 6380
  1. redis集群模式在springboot程序的application.yml里面配置

2.1 Lettuce作为Redis客户端

spring:
  redis:
    cluster:
      nodes: 
        - localhost:7000
        - localhost:7001
        - localhost:7002
    password:  # 如果有密码,填写密码信息
    timeout: 3000
    lettuce:
      pool:
        max-active: 8
        max-idle: 8
        min-idle: 0
        max-wait: -1ms

2.2 Jedis作为客户端

spring:
  redis:
    cluster:
      nodes:
        - localhost:7000
        - localhost:7001
        - localhost:7002
    password:  # 如果有密码,填写密码信息
    timeout: 3000
    jedis:
      pool:
        max-active: 8
        max-idle: 8
        min-idle: 0
        max-wait: -1ms

你可能感兴趣的:(spring,boot,redis,java)