Skip to content

Commit

Permalink
Merge pull request ozimov#4 from MichaelSp/master
Browse files Browse the repository at this point in the history
bind to 127.0.0.1 by default
  • Loading branch information
robertotru authored May 15, 2018
2 parents faa0874 + 3798e30 commit e40e029
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/main/java/redis/embedded/RedisSentinelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class RedisSentinelBuilder {

private File executable;
private RedisExecProvider redisExecProvider = RedisExecProvider.defaultProvider();
private String bind="127.0.0.1";
private Integer port = 26379;
private int masterPort = 6379;
private String masterName = "mymaster";
Expand All @@ -37,6 +38,11 @@ public RedisSentinelBuilder redisExecProvider(RedisExecProvider redisExecProvide
return this;
}

public RedisSentinelBuilder bind(String bind) {
this.bind = bind;
return this;
}

public RedisSentinelBuilder port(Integer port) {
this.port = port;
return this;
Expand Down Expand Up @@ -127,6 +133,7 @@ private void resolveSentinelConf() throws IOException {
if (redisConfigBuilder == null) {
addDefaultReplicationGroup();
}
setting("bind "+bind);
setting(String.format(PORT_LINE, port));
final String configString = redisConfigBuilder.toString();

Expand Down
10 changes: 3 additions & 7 deletions src/main/java/redis/embedded/RedisServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ public class RedisServer extends AbstractRedisInstance {
private static final String REDIS_READY_PATTERN = ".*The server is now ready to accept connections on port.*";
private static final int DEFAULT_REDIS_PORT = 6379;

public RedisServer() throws IOException {
public RedisServer() {
this(DEFAULT_REDIS_PORT);
}

public RedisServer(int port) throws IOException {
public RedisServer(int port) {
super(port);
File executable = RedisExecProvider.defaultProvider().get();
this.args = Arrays.asList(
executable.getAbsolutePath(),
"--port", Integer.toString(port)
);
this.args = builder().port(port).build().args;
}

public RedisServer(File executable, int port) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/embedded/RedisServerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class RedisServerBuilder {

private File executable;
private RedisExecProvider redisExecProvider = RedisExecProvider.defaultProvider();
private String bind="127.0.0.1";
private int port = 6379;
private InetSocketAddress slaveOf;
private String redisConf;
Expand All @@ -28,6 +29,11 @@ public RedisServerBuilder redisExecProvider(RedisExecProvider redisExecProvider)
return this;
}

public RedisServerBuilder bind(String bind) {
this.bind = bind;
return this;
}

public RedisServerBuilder port(int port) {
this.port = port;
return this;
Expand Down Expand Up @@ -66,6 +72,7 @@ public RedisServerBuilder setting(String configLine) {
}

public RedisServer build() {
setting("bind "+bind);
tryResolveConfAndExec();
List<String> args = buildCommandArgs();
return new RedisServer(args, port);
Expand Down

0 comments on commit e40e029

Please sign in to comment.