parent
2347eeb508
commit
99efde6d8a
@ -1,57 +0,0 @@
|
||||
package com.wayn.data.redis.manager;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
/**
|
||||
* redis配置
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Value("${spring.redis.host}")
|
||||
private String host = "127.0.0.1";
|
||||
|
||||
@Value("${spring.redis.port}")
|
||||
private int port = 6379;
|
||||
|
||||
//timeout for jedis try to connect to redis server, not expire time! In milliseconds
|
||||
@Value("${spring.redis.timeout}")
|
||||
private int timeout = 0;
|
||||
|
||||
@Value("${spring.redis.password}")
|
||||
private String password = "";
|
||||
|
||||
@Value("${spring.redis.jedis.pool.max-idle}")
|
||||
private int maxIdle;
|
||||
|
||||
@Value("${spring.redis.maxTotal}")
|
||||
private int maxTotal;
|
||||
|
||||
@Value("${spring.redis.jedis.pool.max-wait}")
|
||||
private int maxWaitMillis;
|
||||
|
||||
@Bean
|
||||
public JedisPoolConfig jedisPoolConfig() {
|
||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||
jedisPoolConfig.setMaxIdle(maxIdle);
|
||||
jedisPoolConfig.setMaxTotal(maxTotal);
|
||||
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
|
||||
return jedisPoolConfig;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JedisPool jedisPool(JedisPoolConfig jedisPoolConfig) {
|
||||
JedisPool jedisPool;
|
||||
if (StringUtils.isNotEmpty(password)) {
|
||||
jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password);
|
||||
} else {
|
||||
jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout);
|
||||
}
|
||||
return jedisPool;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue