diff --git a/src/main/java/redis/embedded/RedisSentinelBuilder.java b/src/main/java/redis/embedded/RedisSentinelBuilder.java index 5e0c8573..49d7f8f5 100644 --- a/src/main/java/redis/embedded/RedisSentinelBuilder.java +++ b/src/main/java/redis/embedded/RedisSentinelBuilder.java @@ -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"; @@ -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; @@ -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(); diff --git a/src/main/java/redis/embedded/RedisServer.java b/src/main/java/redis/embedded/RedisServer.java index 10927f31..79dc4bee 100644 --- a/src/main/java/redis/embedded/RedisServer.java +++ b/src/main/java/redis/embedded/RedisServer.java @@ -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) { diff --git a/src/main/java/redis/embedded/RedisServerBuilder.java b/src/main/java/redis/embedded/RedisServerBuilder.java index affcbbd9..192b9fb6 100644 --- a/src/main/java/redis/embedded/RedisServerBuilder.java +++ b/src/main/java/redis/embedded/RedisServerBuilder.java @@ -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; @@ -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; @@ -66,6 +72,7 @@ public RedisServerBuilder setting(String configLine) { } public RedisServer build() { + setting("bind "+bind); tryResolveConfAndExec(); List args = buildCommandArgs(); return new RedisServer(args, port);