Skip to content

Commit

Permalink
1.modify the parse error in RedisProvider.java
Browse files Browse the repository at this point in the history
  the property of "redis.host" in file "redis.properties" now translate into "host:port:password"
  • Loading branch information
zhouyijiaren committed Nov 5, 2016
1 parent 91c3866 commit 87c24e8
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class RedisProvider extends CacheProvider {
poolConfig.setJmxEnabled(config.getBoolean("redis.pool.jmxEnabled", BaseObjectPoolConfig.DEFAULT_JMX_ENABLE));
poolConfig.setJmxNamePrefix(config.get("redis.pool.jmxNamePrefix", BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX));

//hp[0] is hostname,hp[1] is port,hp[2] is the password of redis
if (shardHost != null) {
String[] shards = shardHost.split(",");
List<JedisShardInfo> shardInfos = new ArrayList<JedisShardInfo>();
Expand All @@ -62,15 +63,19 @@ public class RedisProvider extends CacheProvider {
hp = s.split(":");
shardInfo = new JedisShardInfo(hp[0], Integer.parseInt(hp[1]), timeout);
if (hp.length >= 3) {
shardInfo.setPassword(hp[3]);
shardInfo.setPassword(hp[2]);
}
shardInfos.add(shardInfo);
}
pool = new ShardedJedisPool(poolConfig, shardInfos);
} else {
if (host != null) {
hp = host.split(":");
pool = new JedisPool(poolConfig, hp[0], Integer.parseInt(hp[1]));
if(hp.length >= 3){
pool = new JedisPool(poolConfig, hp[0], Integer.parseInt(hp[1]), timeout, hp[2]);
} else {
pool = new JedisPool(poolConfig, hp[0], Integer.parseInt(hp[1]), timeout);
}
} else {
pool = null;
logger.error("Could not found 'redis.host' or 'redis.shard.host'");
Expand All @@ -97,11 +102,12 @@ private Jedis getJedis() {
if (pool != null && pool instanceof JedisPool) {
jedis = (Jedis) pool.getResource();
}
//hp[0] is hostname,hp[1] is port,hp[2] is the password of redis
if (jedis == null) {
String[] hp = host.split(":");
jedis = new Jedis(hp[0], Integer.parseInt(hp[1]), timeout);
if (hp.length >= 3) {
jedis.auth(hp[3]);
jedis.auth(hp[2]);
}
}
return jedis;
Expand Down

0 comments on commit 87c24e8

Please sign in to comment.