From 1fdf2a94ce4bc1ed8f85ef851678ce53f2295a08 Mon Sep 17 00:00:00 2001 From: ycl Date: Mon, 22 Dec 2025 14:05:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20template/common/src/main/j?= =?UTF-8?q?ava/{{.packagePath}}/common/redis/RedisPoolConfig.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/redis/RedisPoolConfig.java | 57 ------------------- 1 file changed, 57 deletions(-) delete mode 100644 template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolConfig.java diff --git a/template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolConfig.java b/template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolConfig.java deleted file mode 100644 index 85ce928..0000000 --- a/template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolConfig.java +++ /dev/null @@ -1,57 +0,0 @@ -package {{ .package }}.common.redis; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisPoolConfig; -import cn.hutool.core.util.StrUtil; -import org.springframework.beans.factory.annotation.Value; - - - -@Configuration -@EnableConfigurationProperties({RedisPoolProperties.class}) -@ConditionalOnProperty(name = "redis-config.pool.hostAndPort", havingValue = "true") -public class RedisPoolConfig { - @Autowired - private RedisPoolProperties redisPoolProperties; - @Value("${redis-config.pool.password:}") - private String password; - - private JedisPoolConfig initPoolConfig() { - JedisPoolConfig poolConfig = new JedisPoolConfig(); - poolConfig.setMaxTotal(redisPoolProperties.getMaxTotal()); - poolConfig.setMaxIdle(redisPoolProperties.getMaxIdle()); - poolConfig.setMinIdle(redisPoolProperties.getMinIdle()); - poolConfig.setNumTestsPerEvictionRun(redisPoolProperties.getNumTestsPerEvictionRun()); - poolConfig.setTestOnBorrow(redisPoolProperties.isTestOnBorrow()); - poolConfig.setTestOnReturn(redisPoolProperties.isTestOnReturn()); - poolConfig.setTestWhileIdle(redisPoolProperties.isTestWhileIdle()); - poolConfig.setBlockWhenExhausted(redisPoolProperties.isBlockWhenExhausted()); - poolConfig.setJmxEnabled(redisPoolProperties.isJmxEnabled()); - poolConfig.setLifo(redisPoolProperties.isLifo()); - poolConfig.setNumTestsPerEvictionRun(redisPoolProperties.getNumTestsPerEvictionRun()); - poolConfig.setTestOnBorrow(false); - return poolConfig; - } - - - /** - * create jedis poll - * - */ - @Bean - public JedisPool getRedisPool() { - String host = StrUtil.subBefore(redisPoolProperties.getHostAndPort(), ":", false); - int port = Integer.parseInt(StrUtil.subAfter(redisPoolProperties.getHostAndPort(), ":", false)); - if(StrUtil.isNotEmpty(this.password)) { - return new JedisPool(initPoolConfig(),host,port ,1000, password); - }else{ - return new JedisPool(initPoolConfig(),host,port); - } - } - -}