欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot中對應(yīng)2.0.x版本的Redis配置詳解

 更新時間:2022年06月23日 15:40:51   作者:小目標(biāo)青年  
這篇文章主要為大家介紹了SpringBoot中對應(yīng)2.0.x版本的Redis配置詳解,文中的實(shí)現(xiàn)步驟講解詳細(xì),感興趣的小伙伴們可以了解一下

properties格式:

# REDIS (RedisProperties)
# Redis數(shù)據(jù)庫索引(默認(rèn)為0)
spring.redis.database=0
# Redis服務(wù)器地址
spring.redis.host=localhost
# Redis服務(wù)器連接端口
spring.redis.port=6379
# Redis服務(wù)器連接密碼(默認(rèn)為空)
spring.redis.password=
# 連接池最大連接數(shù)(使用負(fù)值表示沒有限制)
spring.redis.jedis.pool.max-active=8
# 連接池最大阻塞等待時間(使用負(fù)值表示沒有限制)
spring.redis.jedis.pool.max-wait=-1
# 連接池中的最大空閑連接
spring.redis.jedis.pool.max-idle=8
# 連接池中的最小空閑連接
spring.redis.jedis.pool.min-idle=0
# 連接超時時間(毫秒)
spring.redis.timeout=5000

yml格式:

目前版本,簡單的連接redis配置文件內(nèi)容如下:

spring:
  redis:
    database: 0
    host: 127.0.0.1
    port: 6379
    password: 12345
    jedis.pool.max-idle: 100
    jedis.pool.max-wait: -1ms
    jedis.pool.min-idle: 2
    timeout: 2000ms

依賴:

<!--用于redis數(shù)據(jù)庫連接-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

如果是使用 lettuce客戶端進(jìn)行連接(我個人非常推薦使用小白菜,畢竟springboot 2.X 之后底層已經(jīng)不再是jedis了,是lettuce):

yml格式

spring:
  redis:
    lettuce:
      pool:
        #連接池最大連接數(shù) 使用負(fù)值代表無限制 默認(rèn)為8
        max-active: 10
        #最大空閑連接 默認(rèn)8
        max-idle: 10
        #最小空閑連接 默認(rèn)0
        min-idle: 1
    host: 127.0.0.1
    password: 12345
    port: 6379
    database: 2
    timeout: 2000ms

 propertie格式

# Redis數(shù)據(jù)庫索引(默認(rèn)為0)
spring.redis.database=2
# Redis服務(wù)器地址
spring.redis.host=127.0.0.1
# Redis服務(wù)器連接端口
spring.redis.port=6379
# Redis服務(wù)器連接密碼(默認(rèn)為空)
spring.redis.password=12345
# 連接池最大連接數(shù)(使用負(fù)值表示沒有限制)
spring.redis.lettuce.pool.max-active=200
# 連接池最大阻塞等待時間(使用負(fù)值表示沒有限制)
spring.redis.lettuce.pool.max-wait=-1
# 連接池中的最大空閑連接
spring.redis.lettuce.pool.max-idle=10
# 連接池中的最小空閑連接
spring.redis.lettuce.pool.min-idle=0
# 連接超時時間(毫秒)
spring.redis.timeout=1000

依賴(如果不使用連接池pool,就不需要加第二個依賴,我推薦還是使用上):

        <!--用于redis數(shù)據(jù)庫連接-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <!--用于redis lettuce 連接池pool使用-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>

到此這篇關(guān)于SpringBoot中對應(yīng)2.0.x版本的Redis配置詳解的文章就介紹到這了,更多相關(guān)SpringBoot Redis配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論