RKeys.count method added. #331

pull/365/head
Nikita 9 years ago
parent 1e8d6df7ec
commit d4719b45d7

@ -257,5 +257,25 @@ public class RedissonKeys implements RKeys {
}, (Object[])keys);
}
@Override
public Long сount() {
return commandExecutor.get(countAsync());
}
@Override
public Future<Long> countAsync() {
return commandExecutor.readAllAsync(RedisCommands.DBSIZE, new SlotCallback<Long, Long>() {
AtomicLong results = new AtomicLong();
@Override
public void onSlotResult(Long result) {
results.addAndGet(result);
}
@Override
public Long onFinish() {
return results.get();
}
});
}
}

@ -187,6 +187,7 @@ public interface RedisCommands {
RedisCommand<Long> HDEL = new RedisStrictCommand<Long>("HDEL", 2, ValueType.MAP_KEY);
RedisStrictCommand<Long> DEL = new RedisStrictCommand<Long>("DEL");
RedisStrictCommand<Long> DBSIZE = new RedisStrictCommand<Long>("DBSIZE");
RedisStrictCommand<Boolean> DEL_SINGLE = new RedisStrictCommand<Boolean>("DEL", new BooleanReplayConvertor());
RedisStrictCommand<Void> DEL_VOID = new RedisStrictCommand<Void>("DEL", new VoidReplayConvertor());

@ -45,6 +45,8 @@ public interface CommandAsyncExecutor {
<R, T> Future<R> writeAllAsync(RedisCommand<T> command, SlotCallback<T, R> callback, Object ... params);
<R, T> Future<R> readAllAsync(RedisCommand<T> command, SlotCallback<T, R> callback, Object ... params);
<T, R> Future<R> evalReadAsync(InetSocketAddress client, String key, Codec codec, RedisCommand<T> evalCommandType, String script, List<Object> keys, Object ... params);
<T, R> Future<R> evalReadAsync(String key, Codec codec, RedisCommand<T> evalCommandType, String script, List<Object> keys, Object ... params);

@ -176,6 +176,11 @@ public class CommandAsyncService implements CommandAsyncExecutor {
return allAsync(false, command, callback, params);
}
@Override
public <R, T> Future<R> readAllAsync(RedisCommand<T> command, SlotCallback<T, R> callback, Object ... params) {
return allAsync(true, command, callback, params);
}
public <T, R> Future<R> allAsync(boolean readOnlyMode, RedisCommand<T> command, final SlotCallback<T, R> callback, Object ... params) {
final Promise<R> mainPromise = connectionManager.newPromise();
Promise<T> promise = new DefaultPromise<T>() {

@ -88,4 +88,11 @@ public interface RKeys extends RKeysAsync {
*/
long delete(String ... keys);
/**
* Returns the number of keys in the currently-selected database
*
* @return
*/
Long сount();
}

@ -71,4 +71,10 @@ public interface RKeysAsync {
*/
Future<Long> deleteAsync(String ... keys);
/**
* Returns the number of keys in the currently-selected database in async mode
*
* @return
*/
Future<Long> countAsync();
}

Loading…
Cancel
Save