unlink, flashdb and flashall async commands support. #965

pull/970/head
Nikita 8 years ago
parent 79f69ff28a
commit 0994aee746

@ -36,6 +36,7 @@ import org.redisson.client.RedisException;
import org.redisson.client.codec.ScanCodec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.RedisStrictCommand;
import org.redisson.client.protocol.decoder.ListScanResult;
import org.redisson.client.protocol.decoder.ScanObjectEntry;
import org.redisson.command.CommandAsyncExecutor;
@ -277,10 +278,24 @@ public class RedissonKeys implements RKeys {
return deleteAsync(keys.toArray(new String[keys.size()]));
}
@Override
public long unlink(String ... keys) {
return commandExecutor.get(deleteAsync(keys));
}
@Override
public RFuture<Long> unlinkAsync(String ... keys) {
return executeAsync(RedisCommands.UNLINK, keys);
}
@Override
public RFuture<Long> deleteAsync(String ... keys) {
return executeAsync(RedisCommands.DEL, keys);
}
private RFuture<Long> executeAsync(RedisStrictCommand<Long> command, String ... keys) {
if (!commandExecutor.getConnectionManager().isClusterMode()) {
return commandExecutor.writeAsync(null, RedisCommands.DEL, keys);
return commandExecutor.writeAsync(null, command, keys);
}
Map<MasterSlaveEntry, List<String>> range2key = new HashMap<MasterSlaveEntry, List<String>>();
@ -320,7 +335,7 @@ public class RedissonKeys implements RKeys {
// executes in batch due to CROSSLOT error
CommandBatchService executorService = new CommandBatchService(commandExecutor.getConnectionManager());
for (String key : entry.getValue()) {
executorService.writeAsync(entry.getKey(), null, RedisCommands.DEL, key);
executorService.writeAsync(entry.getKey(), null, command, key);
}
RFuture<List<?>> future = executorService.executeAsync();
@ -351,6 +366,27 @@ public class RedissonKeys implements RKeys {
});
}
@Override
public void flushdbParallel() {
commandExecutor.get(flushdbParallelAsync());
}
@Override
public RFuture<Void> flushdbParallelAsync() {
return commandExecutor.writeAllAsync(RedisCommands.FLUSHDB_ASYNC);
}
@Override
public void flushallParallel() {
commandExecutor.get(flushallParallelAsync());
}
@Override
public RFuture<Void> flushallParallelAsync() {
return commandExecutor.writeAllAsync(RedisCommands.FLUSHALL_ASYNC);
}
@Override
public void flushdb() {
commandExecutor.get(flushdbAsync());

@ -136,6 +136,16 @@ public abstract class RedissonObject implements RObject {
public RFuture<Boolean> deleteAsync() {
return commandExecutor.writeAsync(getName(), RedisCommands.DEL_BOOL, getName());
}
@Override
public boolean unlink() {
return get(unlinkAsync());
}
@Override
public RFuture<Boolean> unlinkAsync() {
return commandExecutor.writeAsync(getName(), RedisCommands.UNLINK_BOOL, getName());
}
@Override
public boolean touch() {

@ -230,6 +230,17 @@ public interface RKeys extends RKeysAsync {
*/
long delete(String ... keys);
/**
* Delete multiple objects by name.
* Actual removal will happen later asynchronously.
* <p>
* Requires Redis 4.0+
*
* @param keys
* @return number of removed keys
*/
long unlink(String ... keys);
/**
* Returns the number of keys in the currently-selected database
*
@ -242,9 +253,27 @@ public interface RKeys extends RKeysAsync {
*/
void flushdb();
/**
* Delete all keys of currently selected database
* in background without blocking server.
* <p>
* Requires Redis 4.0+
*
*/
void flushdbParallel();
/**
* Delete all keys of all existing databases
*/
void flushall();
/**
* Delete all keys of all existing databases
* in background without blocking server.
* <p>
* Requires Redis 4.0+
*
*/
void flushallParallel();
}

@ -188,6 +188,17 @@ public interface RKeysAsync {
*/
RFuture<Long> deleteAsync(String ... keys);
/**
* Delete multiple objects by name.
* Actual removal will happen later asynchronously.
* <p>
* Requires Redis 4.0+
*
* @param keys
* @return number of removed keys
*/
RFuture<Long> unlinkAsync(String ... keys);
/**
* Returns the number of keys in the currently-selected database in async mode
*
@ -207,4 +218,24 @@ public interface RKeysAsync {
*/
RFuture<Void> flushallAsync();
/**
* Delete all keys of currently selected database
* in background without blocking server.
* <p>
* Requires Redis 4.0+
*
* @return void
*/
RFuture<Void> flushdbParallelAsync();
/**
* Delete all keys of all existing databases
* in background without blocking server.
* <p>
* Requires Redis 4.0+
*
* @return void
*/
RFuture<Void> flushallParallelAsync();
}

@ -63,6 +63,16 @@ public interface RObject extends RObjectAsync {
*/
boolean delete();
/**
* Delete the objects.
* Actual removal will happen later asynchronously.
* <p>
* Requires Redis 4.0+
*
* @return <code>true</code> if it was exist and deleted else <code>false</code>
*/
boolean unlink();
/**
* Rename current object key to <code>newName</code>
*

@ -56,6 +56,16 @@ public interface RObjectAsync {
*/
RFuture<Boolean> deleteAsync();
/**
* Delete the objects.
* Actual removal will happen later asynchronously.
* <p>
* Requires Redis 4.0+
*
* @return <code>true</code> if it was exist and deleted else <code>false</code>
*/
RFuture<Boolean> unlinkAsync();
/**
* Rename current object key to <code>newName</code>
* in async mode

@ -245,6 +245,9 @@ public interface RedisCommands {
RedisStrictCommand<String> CLIENT_GETNAME = new RedisStrictCommand<String>("CLIENT", "GETNAME", new StringDataDecoder());
RedisStrictCommand<Void> FLUSHDB = new RedisStrictCommand<Void>("FLUSHDB", new VoidReplayConvertor());
RedisStrictCommand<Void> FLUSHALL = new RedisStrictCommand<Void>("FLUSHALL", new VoidReplayConvertor());
RedisStrictCommand<Void> FLUSHDB_ASYNC = new RedisStrictCommand<Void>("FLUSHDB", "ASYNC", new VoidReplayConvertor());
RedisStrictCommand<Void> FLUSHALL_ASYNC = new RedisStrictCommand<Void>("FLUSHALL", "ASYNC", new VoidReplayConvertor());
RedisStrictCommand<List<String>> KEYS = new RedisStrictCommand<List<String>>("KEYS", new StringListReplayDecoder());
RedisCommand<List<Object>> MGET = new RedisCommand<List<Object>>("MGET", new ObjectListReplayDecoder<Object>());
@ -272,6 +275,9 @@ public interface RedisCommands {
RedisStrictCommand<Boolean> DEL_BOOL = new RedisStrictCommand<Boolean>("DEL", new BooleanNullSafeReplayConvertor());
RedisStrictCommand<Boolean> DEL_OBJECTS = new RedisStrictCommand<Boolean>("DEL", new BooleanNullSafeReplayConvertor());
RedisStrictCommand<Void> DEL_VOID = new RedisStrictCommand<Void>("DEL", new VoidReplayConvertor());
RedisStrictCommand<Long> UNLINK = new RedisStrictCommand<Long>("UNLINK");
RedisStrictCommand<Boolean> UNLINK_BOOL = new RedisStrictCommand<Boolean>("UNLINK", new BooleanNullSafeReplayConvertor());
RedisCommand<Object> GET = new RedisCommand<Object>("GET");
RedisStrictCommand<Long> GET_LONG = new RedisStrictCommand<Long>("GET", new LongReplayConvertor());

Loading…
Cancel
Save