Skip to content
Permalink
Browse files
修复redis连接加入database参数问题 (#742)
* fix:修复redis连接加入database参数问题
fix:修复redis获取元信息获取不到问题

* fix:优化代码
  • Loading branch information
dcy421 committed Apr 25, 2021
1 parent fd54e4d commit 4d07e446d7856cf7c5f117fb09e33a7b025088ef
Showing 1 changed file with 4 additions and 3 deletions.
@@ -44,9 +44,9 @@
public class RedisMetaDataCollector implements MetaDataCollector {

private final static Logger logger = LoggerFactory.getLogger(RedisMetaDataCollector.class);
private final static String REDIS_DATABASE_KEY = "database";
private URL url;
private JedisPool pool;
private static final String META_DATA_SOTRE_TAG = ".metaData";
Set<HostAndPort> jedisClusterNodes;
private int timeout;
private String password;
@@ -73,7 +73,8 @@ public void init() {
jedisClusterNodes.add(new HostAndPort(tmpUrl.getHost(), tmpUrl.getPort()));
}
} else {
pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort(), timeout, url.getPassword());
int database = url.getParameter(REDIS_DATABASE_KEY, 0);
pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort(), timeout, url.getPassword(), database);
}
}

@@ -98,7 +99,7 @@ private String doGetMetaData(MetadataIdentifier identifier) {
}
} else {
try (Jedis jedis = pool.getResource()) {
result = jedis.get(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY) + META_DATA_SOTRE_TAG);
result = jedis.get(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
} catch (Throwable e) {
logger.error("Failed to get " + identifier + " from redis, cause: " + e.getMessage(), e);
throw new RpcException("Failed to get " + identifier + " from redis, cause: " + e.getMessage(), e);

0 comments on commit 4d07e44

Please sign in to comment.