Skip to content

Commit

Permalink
Allow hostnames in MasterSlaveTopologyProvider when parsing in master…
Browse files Browse the repository at this point in the history
…_host #377

Add dash to allow hostnames in when parsing master_host details received from Redis. Previously, parsing of hostnames with a dash failed due to a restrictive regex.
  • Loading branch information
mp911de committed Oct 24, 2016
1 parent 7d58389 commit 0d5f3f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MasterSlaveTopologyProvider implements TopologyProvider {

public static final Pattern ROLE_PATTERN = Pattern.compile("^role\\:([a-z]+)$", Pattern.MULTILINE);
public static final Pattern SLAVE_PATTERN = Pattern.compile("^slave(\\d+)\\:([a-zA-Z\\,\\=\\d\\.\\:]+)$", Pattern.MULTILINE);
public static final Pattern MASTER_HOST_PATTERN = Pattern.compile("^master_host\\:([a-zA-Z\\,\\=\\d\\.\\:]+)$",
public static final Pattern MASTER_HOST_PATTERN = Pattern.compile("^master_host\\:([a-zA-Z\\,\\=\\d\\.\\:\\-]+)$",
Pattern.MULTILINE);
public static final Pattern MASTER_PORT_PATTERN = Pattern.compile("^master_port\\:(\\d+)$", Pattern.MULTILINE);
public static final Pattern IP_PATTERN = Pattern.compile("ip\\=([a-zA-Z\\d\\.\\:]+)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ public void shouldParseMasterAndSlave() throws Exception {
assertThat(master.getUri().getHost()).isEqualTo("127.0.0.1");
}

@Test
public void shouldParseMasterHostname() throws Exception {

String info = "# Replication\r\n" + "role:slave\r\n" + "connected_slaves:1\r\n" + "master_host:my.Host-name.COM\r\n"
+ "master_port:1234\r\n" + "master_repl_offset:56276\r\n" + "repl_backlog_active:1\r\n";

List<RedisNodeDescription> result = sut.getNodesFromInfo(info);
assertThat(result).hasSize(2);

RedisNodeDescription slave = result.get(0);
assertThat(slave.getRole()).isEqualTo(RedisInstance.Role.SLAVE);

RedisNodeDescription master = result.get(1);
assertThat(master.getRole()).isEqualTo(RedisInstance.Role.MASTER);
assertThat(master.getUri().getHost()).isEqualTo("my.Host-name.COM");
}

@Test
public void shouldParseIPv6MasterAddress() throws Exception {

Expand Down

0 comments on commit 0d5f3f8

Please sign in to comment.