From 0bb53edd3b0732737f8de3b2b3c77d891219fa9e Mon Sep 17 00:00:00 2001 From: ycl Date: Mon, 18 May 2026 16:18:55 +0800 Subject: [PATCH] #init commit --- .../common/redis/RedisPoolConfig.java | 60 -------- .../common/redis/RedisPoolProperties.java | 145 ------------------ 2 files changed, 205 deletions(-) delete mode 100644 template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolConfig.java delete mode 100644 template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolProperties.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 bf6d30e..0000000 --- a/template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolConfig.java +++ /dev/null @@ -1,60 +0,0 @@ -package {{ .package }}.common.redis; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import redis.clients.jedis.HostAndPort; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import redis.clients.jedis.JedisCluster; -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") -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); - } - } - -} diff --git a/template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolProperties.java b/template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolProperties.java deleted file mode 100644 index f61c8ec..0000000 --- a/template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolProperties.java +++ /dev/null @@ -1,145 +0,0 @@ -package {{ .package }}.common.redis; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -@Configuration -@ConfigurationProperties(prefix = "redis-config.pool") -public class RedisPoolProperties { - private String hostAndPort; - private int maxTotal; - private int maxIdle; - private int minIdle; - private Long maxWaitMillis; - private Long timeBetweenEvictionRunsMillis; - private Long minEvictableIdleTimeMillis; - private Long softMinEvictableIdleTimeMillis; - private boolean testOnBorrow; - private boolean testOnReturn; - private boolean testWhileIdle; - private boolean blockWhenExhausted; - private boolean jmxEnabled; - private boolean lifo; - private int numTestsPerEvictionRun; - - public String getHostAndPort() { - return hostAndPort; - } - - public void setHostAndPort(String hostAndPort) { - this.hostAndPort = hostAndPort; - } - - public int getMaxTotal() { - return maxTotal; - } - - public void setMaxTotal(int maxTotal) { - this.maxTotal = maxTotal; - } - - public int getMaxIdle() { - return maxIdle; - } - - public void setMaxIdle(int maxIdle) { - this.maxIdle = maxIdle; - } - - public int getMinIdle() { - return minIdle; - } - - public void setMinIdle(int minIdle) { - this.minIdle = minIdle; - } - - public Long getMaxWaitMillis() { - return maxWaitMillis; - } - - public void setMaxWaitMillis(Long maxWaitMillis) { - this.maxWaitMillis = maxWaitMillis; - } - - public Long getTimeBetweenEvictionRunsMillis() { - return timeBetweenEvictionRunsMillis; - } - - public void setTimeBetweenEvictionRunsMillis(Long timeBetweenEvictionRunsMillis) { - this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; - } - - public Long getMinEvictableIdleTimeMillis() { - return minEvictableIdleTimeMillis; - } - - public void setMinEvictableIdleTimeMillis(Long minEvictableIdleTimeMillis) { - this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; - } - - public Long getSoftMinEvictableIdleTimeMillis() { - return softMinEvictableIdleTimeMillis; - } - - public void setSoftMinEvictableIdleTimeMillis(Long softMinEvictableIdleTimeMillis) { - this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; - } - - public boolean isTestOnBorrow() { - return testOnBorrow; - } - - public void setTestOnBorrow(boolean testOnBorrow) { - this.testOnBorrow = testOnBorrow; - } - - public boolean isTestOnReturn() { - return testOnReturn; - } - - public void setTestOnReturn(boolean testOnReturn) { - this.testOnReturn = testOnReturn; - } - - public boolean isTestWhileIdle() { - return testWhileIdle; - } - - public void setTestWhileIdle(boolean testWhileIdle) { - this.testWhileIdle = testWhileIdle; - } - - public boolean isBlockWhenExhausted() { - return blockWhenExhausted; - } - - public void setBlockWhenExhausted(boolean blockWhenExhausted) { - this.blockWhenExhausted = blockWhenExhausted; - } - - public boolean isJmxEnabled() { - return jmxEnabled; - } - - public void setJmxEnabled(boolean jmxEnabled) { - this.jmxEnabled = jmxEnabled; - } - - public boolean isLifo() { - return lifo; - } - - public void setLifo(boolean lifo) { - this.lifo = lifo; - } - - public int getNumTestsPerEvictionRun() { - return numTestsPerEvictionRun; - } - - public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) { - this.numTestsPerEvictionRun = numTestsPerEvictionRun; - } -}