From b53e923bfc16d414d35fc146037f59bc1957a49d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Tue, 15 Feb 2022 23:22:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor(RedissonConfig.java):=20Redisson?= =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8F=E9=94=81=E9=85=8D=E7=BD=AE=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../youlai/common/redis/RedissonConfig.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/youlai-common/common-redis/src/main/java/com/youlai/common/redis/RedissonConfig.java b/youlai-common/common-redis/src/main/java/com/youlai/common/redis/RedissonConfig.java index a5a96f549..7a4b9722f 100644 --- a/youlai-common/common-redis/src/main/java/com/youlai/common/redis/RedissonConfig.java +++ b/youlai-common/common-redis/src/main/java/com/youlai/common/redis/RedissonConfig.java @@ -1,47 +1,47 @@ package com.youlai.common.redis; import cn.hutool.core.util.StrUtil; +import lombok.Setter; import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.config.Config; import org.redisson.config.SingleServerConfig; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** - * 分布式锁 Redisson net配置 + * 分布式锁 Redisson 配置 * * @author huawei * @email huawei_code@163.com * @date 2021/2/22 */ +@ConditionalOnProperty(prefix = "redisson",name = "address") +@ConfigurationProperties(prefix = "redisson") @Configuration public class RedissonConfig { - @Value("${spring.redis.host}") - private String host; - @Value("${spring.redis.port}") - private Integer port; - @Value("${spring.redis.password}") + @Setter + private String address; + @Setter private String password; - @Value("${spring.redis.database}") + @Setter private Integer database; - - @Value("${spring.redis.lettuce.pool.min-idle}") - private Integer connectionMinimumIdleSize = 1;// 默认最小空闲连接数 + @Setter + private Integer minIdle;// 默认最小空闲连接数 @Bean public RedissonClient redissonClient() { Config config = new Config(); SingleServerConfig singleServerConfig = config.useSingleServer(); - singleServerConfig.setAddress("redis://" + host + ":" + port); + singleServerConfig.setAddress(address); singleServerConfig.setDatabase(database); - singleServerConfig.setConnectionMinimumIdleSize(connectionMinimumIdleSize); - if(StrUtil.isNotBlank(password)){ + singleServerConfig.setConnectionMinimumIdleSize(minIdle); + if (StrUtil.isNotBlank(password)) { singleServerConfig.setPassword(password); } - singleServerConfig.setConnectTimeout(10000); return Redisson.create(config); }