删除 template/common/src/main/java/{{.packagePath}}/common/redis/RedisPoolConfig.java

This commit is contained in:
ycl
2025-12-22 14:05:22 +08:00
parent 65196d36bc
commit 1fdf2a94ce

View File

@@ -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);
}
}
}