Skip to content

Commit

Permalink
Broadcast commands listed in redis#3303 (redis#3306)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Feb 28, 2023
1 parent 6d60ed6 commit 519faa3
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 120 deletions.
18 changes: 18 additions & 0 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public final CommandObject<String> flushAll() {
return FLUSHALL_COMMAND_OBJECT;
}

private final CommandObject<String> FLUSHDB_COMMAND_OBJECT = new CommandObject<>(commandArguments(FLUSHDB), BuilderFactory.STRING);

public final CommandObject<String> flushDB() {
return FLUSHDB_COMMAND_OBJECT;
}

public final CommandObject<String> configSet(String parameter, String value) {
return new CommandObject<>(commandArguments(Command.CONFIG).add(Keyword.SET).add(parameter).add(value), BuilderFactory.STRING);
}
Expand Down Expand Up @@ -2812,6 +2818,12 @@ public final CommandObject<String> scriptFlush(String sampleKey, FlushMode flush
return new CommandObject<>(commandArguments(SCRIPT).add(FLUSH).add(flushMode).processKey(sampleKey), BuilderFactory.STRING);
}

private final CommandObject<String> SCRIPT_KILL_COMMAND_OBJECT = new CommandObject<>(commandArguments(SCRIPT).add(KILL), BuilderFactory.STRING);

public final CommandObject<String> scriptKill() {
return SCRIPT_KILL_COMMAND_OBJECT;
}

public final CommandObject<String> scriptKill(String sampleKey) {
return new CommandObject<>(commandArguments(SCRIPT).add(KILL).processKey(sampleKey), BuilderFactory.STRING);
}
Expand All @@ -2837,6 +2849,12 @@ public final CommandObject<String> scriptKill(byte[] sampleKey) {
return new CommandObject<>(commandArguments(SCRIPT).add(KILL).processKey(sampleKey), BuilderFactory.STRING);
}

private final CommandObject<String> SLOWLOG_RESET_COMMAND_OBJECT = new CommandObject<>(commandArguments(SLOWLOG).add(RESET), BuilderFactory.STRING);

public final CommandObject<String> slowlogReset() {
return SLOWLOG_RESET_COMMAND_OBJECT;
}

public final CommandObject<Object> fcall(String name, List<String> keys, List<String> args) {
String[] keysArray = keys.toArray(new String[keys.size()]);
String[] argsArray = args.toArray(new String[args.size()]);
Expand Down
205 changes: 100 additions & 105 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,104 @@ public int getDB() {
return this.db;
}

/**
* @return <code>PONG</code>
*/
@Override
public String ping() {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.PING);
return connection.getStatusCodeReply();
}

/**
* Works same as {@link Jedis#ping()} but returns argument message instead of <code>PONG</code>.
* @param message
* @return message
*/
public byte[] ping(final byte[] message) {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.PING, message);
return connection.getBinaryBulkReply();
}

/**
* Select the DB with having the specified zero-based numeric index. For default every new
* connection connection is automatically selected to DB 0.
* @param index
* @return OK
*/
@Override
public String select(final int index) {
checkIsInMultiOrPipeline();
connection.sendCommand(SELECT, toByteArray(index));
String statusCodeReply = connection.getStatusCodeReply();
this.db = index;
return statusCodeReply;
}

@Override
public String swapDB(final int index1, final int index2) {
checkIsInMultiOrPipeline();
connection.sendCommand(SWAPDB, toByteArray(index1), toByteArray(index2));
return connection.getStatusCodeReply();
}

/**
* Delete all the keys of the currently selected DB. This command never fails.
* @return OK
*/
@Override
public String flushDB() {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.flushDB());
}

/**
* Delete all the keys of the currently selected DB. This command never fails.
* @param flushMode
* @return OK
*/
@Override
public String flushDB(FlushMode flushMode) {
checkIsInMultiOrPipeline();
connection.sendCommand(FLUSHDB, flushMode.getRaw());
return connection.getStatusCodeReply();
}

/**
* Delete all the keys of all the existing databases, not just the currently selected one. This
* command never fails.
* @return OK
*/
@Override
public String flushAll() {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.flushAll());
}

/**
* Delete all the keys of all the existing databases, not just the currently selected one. This
* command never fails.
* @param flushMode
* @return OK
*/
@Override
public String flushAll(FlushMode flushMode) {
checkIsInMultiOrPipeline();
connection.sendCommand(FLUSHALL, flushMode.getRaw());
return connection.getStatusCodeReply();
}

/**
* Ask the server to silently close the connection.
*/
@Override
public String quit() {
checkIsInMultiOrPipeline();
return connection.quit();
}

/**
* COPY source destination [DB destination-db] [REPLACE]
*
Expand Down Expand Up @@ -346,27 +444,6 @@ public boolean copy(byte[] srcKey, byte[] dstKey, boolean replace) {
return connection.executeCommand(commandObjects.copy(srcKey, dstKey, replace));
}

/**
* @return <code>PONG</code>
*/
@Override
public String ping() {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.PING);
return connection.getStatusCodeReply();
}

/**
* Works same as {@link Jedis#ping()} but returns argument message instead of <code>PONG</code>.
* @param message
* @return message
*/
public byte[] ping(final byte[] message) {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.PING, message);
return connection.getBinaryBulkReply();
}

/**
* Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1
* GB).
Expand Down Expand Up @@ -440,15 +517,6 @@ public byte[] getEx(final byte[] key, final GetExParams params) {
return connection.executeCommand(commandObjects.getEx(key, params));
}

/**
* Ask the server to silently close the connection.
*/
@Override
public String quit() {
checkIsInMultiOrPipeline();
return connection.quit();
}

/**
* Test if the specified keys exist. The command returns the number of keys exist.
* Time complexity: O(N)
Expand Down Expand Up @@ -531,29 +599,6 @@ public String type(final byte[] key) {
return connection.executeCommand(commandObjects.type(key));
}

/**
* Delete all the keys of the currently selected DB. This command never fails.
* @return OK
*/
@Override
public String flushDB() {
checkIsInMultiOrPipeline();
connection.sendCommand(FLUSHDB);
return connection.getStatusCodeReply();
}

/**
* Delete all the keys of the currently selected DB. This command never fails.
* @param flushMode
* @return OK
*/
@Override
public String flushDB(FlushMode flushMode) {
checkIsInMultiOrPipeline();
connection.sendCommand(FLUSHDB, flushMode.getRaw());
return connection.getStatusCodeReply();
}

/**
* Returns all the keys matching the glob-style pattern as space separated strings. For example if
* you have in the database the keys "foo" and "foobar" the command "KEYS foo*" will return
Expand Down Expand Up @@ -714,7 +759,6 @@ public long pexpireTime(final byte[] key) {
return connection.executeCommand(commandObjects.pexpireTime(key));
}


/**
* EXPIREAT works exactly like {@link Jedis#expire(byte[], long) EXPIRE} but instead to get the
* number of seconds representing the Time To Live of the key as a second argument (that is a
Expand Down Expand Up @@ -793,28 +837,6 @@ public long touch(final byte[] key) {
return connection.executeCommand(commandObjects.touch(key));
}

/**
* Select the DB with having the specified zero-based numeric index. For default every new
* connection connection is automatically selected to DB 0.
* @param index
* @return OK
*/
@Override
public String select(final int index) {
checkIsInMultiOrPipeline();
connection.sendCommand(SELECT, toByteArray(index));
String statusCodeReply = connection.getStatusCodeReply();
this.db = index;
return statusCodeReply;
}

@Override
public String swapDB(final int index1, final int index2) {
checkIsInMultiOrPipeline();
connection.sendCommand(SWAPDB, toByteArray(index1), toByteArray(index2));
return connection.getStatusCodeReply();
}

/**
* Move the specified key from the currently selected DB to the specified destination DB. Note
* that this command returns 1 only if the key was successfully moved, and 0 if the target key was
Expand All @@ -832,31 +854,6 @@ public long move(final byte[] key, final int dbIndex) {
return connection.getIntegerReply();
}

/**
* Delete all the keys of all the existing databases, not just the currently selected one. This
* command never fails.
* @return OK
*/
@Override
public String flushAll() {
checkIsInMultiOrPipeline();
connection.sendCommand(FLUSHALL);
return connection.getStatusCodeReply();
}

/**
* Delete all the keys of all the existing databases, not just the currently selected one. This
* command never fails.
* @param flushMode
* @return OK
*/
@Override
public String flushAll(FlushMode flushMode) {
checkIsInMultiOrPipeline();
connection.sendCommand(FLUSHALL, flushMode.getRaw());
return connection.getStatusCodeReply();
}

/**
* GETSET is an atomic set this value and return the old value command. Set key to the string
* value and return the old value stored at key. The string can't be longer than 1073741824 bytes
Expand Down Expand Up @@ -3887,14 +3884,12 @@ public byte[] scriptLoad(final byte[] script) {

@Override
public String scriptKill() {
connection.sendCommand(SCRIPT, KILL);
return connection.getStatusCodeReply();
return connection.executeCommand(commandObjects.scriptKill());
}

@Override
public String slowlogReset() {
connection.sendCommand(SLOWLOG, Keyword.RESET);
return connection.getBulkReply();
return connection.executeCommand(commandObjects.slowlogReset());
}

@Override
Expand Down
Loading

0 comments on commit 519faa3

Please sign in to comment.