Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwujing committed Nov 25, 2019
1 parent 355edb7 commit 6181ba6
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions springboot-redis/src/main/java/com/pancm/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,25 @@ public class RedisConfig {
@Value("${redis.timeBetweenEvictionRunsMillis}")
private long timeBetweenEvictionRunsMillis;

@Value("${redis.testOnBorrow}")
private boolean testOnBorrow;

@Value("${redis.testWhileIdle}")
private boolean testWhileIdle;
// @Value("${redis.testOnBorrow}")
// private boolean testOnBorrow;
//
// @Value("${redis.testWhileIdle")
// private boolean testWhileIdle;

@Value("${redis.cluster.max-redirects}")
private Integer mmaxRedirectsac;

@Value("${redis.password}")
private String redispwd;

@Value("${spring.redis.host}")
private String host;

@Value("${spring.redis.port}")
private Integer port;


/**
* JedisPoolConfig 连接池
*
Expand All @@ -75,9 +82,9 @@ public JedisPoolConfig jedisPoolConfig() {
// 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
jedisPoolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
// 是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个
jedisPoolConfig.setTestOnBorrow(testOnBorrow);
// jedisPoolConfig.setTestOnBorrow(testOnBorrow);
// 在空闲时检查有效性, 默认false
jedisPoolConfig.setTestWhileIdle(testWhileIdle);
// jedisPoolConfig.setTestWhileIdle(testWhileIdle);
return jedisPoolConfig;
}

Expand All @@ -89,16 +96,18 @@ public JedisPoolConfig jedisPoolConfig() {
*/
@Bean
public JedisConnectionFactory JedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {
JedisConnectionFactory JedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);
/*
* 设置密码,如果为空,则不设置
* 可在 redis.conf 文件中设置: requirepass 密码
*/

if (redispwd == null || redispwd.length() == 0) {
JedisConnectionFactory.setPassword(redispwd);
jedisConnectionFactory.setPassword(redispwd);
}
return JedisConnectionFactory;
jedisConnectionFactory.setHostName(host);
jedisConnectionFactory.setPort(port);
return jedisConnectionFactory;
}

/**
Expand Down

0 comments on commit 6181ba6

Please sign in to comment.