#init commit
This commit is contained in:
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user