---
title: "Boot Redis连单机、哨兵、集群模式代码"
author: "jdkleo"
date: "2021-01-14T14:35:01Z"
tags: []
categories: ["编程语言"]
slug: "boot-redis"
draft: false
lastmod: "2021-01-14T14:38:09Z"
id: 2518695
url: "https://jdkleo.iteye.com/blog/2518695"
---

```
  redis:
#      #-- 单机模式 --
#      # redis数据库索引（默认为0）
#      database: 0
#      # redis服务器地址（默认为localhost） 单节点：redis.test.xxx.com:6379
#      host: redis.test.xxx.com
#      # redis端口（默认为6379）
#      port: 6379
#      # redis访问密码（默认为空）
      password: foobared
#      # redis连接超时时间（单位为毫秒）
#      timeout: 2000

      #-- 哨兵模式 --
      sentinel:
        master: imaster  #主10.6.85.21 从10.6.168.250 sentinel 10.6.85.23
        nodes:
          - redis1.test.xxx.com:26379
          - redis2.test.xxx.com:26379
          - redis3.test.xxx.com:26379

      #-- 集群模式 --
#     cluster:
#        nodes:
#          - redis1.test.xxx.com:26379
#          - redis2.test.xxx.com:26379
#          - redis3.test.xxx.com:26379

      # redis连接池配置
      jedis:
        pool:
          # 最大可用连接数（默认为8，负数表示无限）
          max-active: 800
          # 最大空闲连接数（默认为8，负数表示无限）
          max-idle: 100
          # 最小空闲连接数（默认为0，该值只有为正数才有作用）
          min-idle: 100
          # 从连接池中获取连接最大等待时间（默认为-1，单位为毫秒，负数表示无限）
          max-wait: 100
```