Skip to content
Browse files

SLAVEOF (synch and asynch) | ad hoc tested (need to add tests to test…

…suite)
  • Loading branch information...
1 parent 385c7d2 commit d7a775c795dd5ae7ef70e0f7144f735cf46e1e07 @alphazero committed Mar 10, 2010
View
13 core/api/src/main/java/org/jredis/JRedis.java
@@ -764,4 +764,17 @@
* @throws RedisException
*/
public Map<String, String> info () throws RedisException;
+
+ /**
+ * @Redis SLAVEOF
+ * @param host ip address
+ * @param port
+ */
+ public void slaveof(String host, int port) throws RedisException;
+
+ /**
+ * Convenience method. Turns off replication.
+ * @Redis SLAVEOF "no one"
+ */
+ public void slaveofnone() throws RedisException;
}
View
13 core/api/src/main/java/org/jredis/JRedisFuture.java
@@ -699,4 +699,17 @@
* @return
*/
public Future<Map<String, String>> info () ;
+
+ /**
+ * @Redis SLAVEOF
+ * @param host ip address
+ * @param port
+ */
+ public Future<ResponseStatus> slaveof(String host, int port);
+
+ /**
+ * Convenience method. Turns off replication.
+ * @Redis SLAVEOF "no one"
+ */
+ public Future<ResponseStatus> slaveofnone();
}
View
3 core/api/src/main/java/org/jredis/protocol/Command.java
@@ -123,7 +123,8 @@
// Remote server control commands
INFO (RequestType.NO_ARG, ResponseType.BULK),
- MONITOR (RequestType.NO_ARG, ResponseType.VIRTUAL);
+ MONITOR (RequestType.NO_ARG, ResponseType.VIRTUAL),
+ SLAVEOF (RequestType.KEY_KEY, ResponseType.STATUS);
/** semantic sugar */
public final String code;
View
17 core/ri/src/main/java/org/jredis/ri/alphazero/JRedisFutureSupport.java
@@ -33,6 +33,7 @@
import org.jredis.JRedisFuture;
import org.jredis.KeyValueSet;
import org.jredis.ProviderException;
+import org.jredis.RedisException;
import org.jredis.RedisType;
import org.jredis.Sort;
import org.jredis.connector.Connection;
@@ -128,6 +129,22 @@ public FutureStatus flushdb() {
// this.queueRequest(Command.SELECT, Convert.toBytes(index));
// return this;
// }
+
+ public Future<ResponseStatus> slaveof(String host, int port) {
+ byte[] hostbytes = null;
+ if((hostbytes = getKeyBytes(host)) == null)
+ throw new IllegalArgumentException ("invalid host => ["+host+"]");
+
+ byte[] portbytes = null;
+ if((portbytes = Convert.toBytes(port)) == null)
+ throw new IllegalArgumentException ("invalid port => ["+port+"]");
+
+ return new FutureStatus(this.queueRequest(Command.SLAVEOF, hostbytes, portbytes));
+ }
+ public Future<ResponseStatus> slaveofnone() {
+ return new FutureStatus(this.queueRequest(Command.SLAVEOF, "no".getBytes(), "one".getBytes()));
+ }
+
// @Override
public FutureStatus rename(String oldkey, String newkey) {
byte[] oldkeydata = null;
View
17 core/ri/src/main/java/org/jredis/ri/alphazero/JRedisSupport.java
@@ -145,6 +145,23 @@ public JRedis flushdb() throws RedisException {
// this.serviceRequest(Command.SELECT, Convert.toBytes(index));
// return this;
// }
+
+ public void slaveof(String host, int port) throws RedisException{
+ byte[] hostbytes = null;
+ if((hostbytes = getKeyBytes(host)) == null)
+ throw new IllegalArgumentException ("invalid host => ["+host+"]");
+
+ byte[] portbytes = null;
+ if((portbytes = Convert.toBytes(port)) == null)
+ throw new IllegalArgumentException ("invalid port => ["+port+"]");
+
+ this.serviceRequest(Command.SLAVEOF, hostbytes, portbytes);
+ }
+
+ public void slaveofnone() throws RedisException{
+ this.serviceRequest(Command.SLAVEOF, "no".getBytes(), "one".getBytes());
+ }
+
// @Override
public void rename(String oldkey, String newkey) throws RedisException {
byte[] oldkeydata = null;

0 comments on commit d7a775c

Please sign in to comment.
Something went wrong with that request. Please try again.