提交 4c95cfe9 编写于 作者: K ken.lj

Fixed #665, redis registry support password auth

上级 c7695d4f
......@@ -20,6 +20,7 @@ import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.NamedThreadFactory;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.common.utils.UrlUtils;
import com.alibaba.dubbo.registry.NotifyListener;
import com.alibaba.dubbo.registry.support.FailbackRegistry;
......@@ -117,6 +118,8 @@ public class RedisRegistry extends FailbackRegistry {
if (backups != null && backups.length > 0) {
addresses.addAll(Arrays.asList(backups));
}
String password = url.getPassword();
for (String address : addresses) {
int i = address.indexOf(':');
String host;
......@@ -128,8 +131,13 @@ public class RedisRegistry extends FailbackRegistry {
host = address;
port = DEFAULT_REDIS_PORT;
}
this.jedisPools.put(address, new JedisPool(config, host, port,
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)));
if (StringUtils.isEmpty(password)) {
this.jedisPools.put(address, new JedisPool(config, host, port,
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)));
} else {
this.jedisPools.put(address, new JedisPool(config, host, port,
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), password));
}
}
this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD);
......
......@@ -30,10 +30,12 @@ public class RedisRegistryTest {
String service = "com.alibaba.dubbo.test.injvmServie";
URL registryUrl = URL.valueOf("redis://239.255.255.255/");
URL registryUrlWithPasswd = URL.valueOf("zookeeper://239.255.255.255?password=123456");
URL serviceUrl = URL.valueOf("redis://redis/" + service
+ "?notify=false&methods=test1,test2");
URL consumerUrl = URL.valueOf("redis://consumer/" + service + "?notify=false&methods=test1,test2");
// RedisRegistry registry = new RedisRegistry(registryUrl);
// RedisRegistry registryWithPasswd = new RedisRegistry(registryUrlWithPasswd);
/**
* @throws java.lang.Exception
......@@ -47,7 +49,7 @@ public class RedisRegistryTest {
*/
@Before
public void setUp() throws Exception {
//registry.register(service, serviceUrl);
//registry.register(serviceUrl);
}
/**
......@@ -92,4 +94,9 @@ public class RedisRegistryTest {
}
@Test
public void testRedisPasswd() {
// Assert.assertNotNull(registryWithPasswd);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册