DATAREDIS-635 - Polishing.

Update Javadoc and format code a bit.

Original Pull Request: #296
This commit is contained in:
Christoph Strobl
2018-03-16 09:17:20 +01:00
parent c18a311aa9
commit 09bd48c245
3 changed files with 26 additions and 8 deletions

View File

@@ -171,10 +171,18 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
throw new InvalidDataAccessApiUsageException("Scan is not supported across multiple nodes within a cluster");
}
/**
* Use a {@link Cursor} to iterate over keys stored at the given {@link RedisClusterNode}.
*
* @param node must not be {@literal null}.
* @param options must not be {@literal null}.
* @return never {@literal null}.
* @since 2.1
*/
Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options) {
Assert.notNull(node, "RedisClusterNode must not be null!");
Assert.notNull(options, "Pattern must not be null!");
Assert.notNull(options, "Options must not be null!");
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<Cursor<byte[]>>) client -> {

View File

@@ -183,10 +183,18 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
.getValue());
}
/**
* Use a {@link Cursor} to iterate over keys stored at the given {@link RedisClusterNode}.
*
* @param node must not be {@literal null}.
* @param options must not be {@literal null}.
* @return never {@literal null}.
* @since 2.1
*/
Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options) {
Assert.notNull(node, "RedisClusterNode must not be null!");
Assert.notNull(options, "Pattern must not be null!");
Assert.notNull(options, "Options must not be null!");
return connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((LettuceClusterCommandCallback<ScanCursor<byte[]>>) client -> {
@@ -195,12 +203,11 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
@Override
protected LettuceScanIteration<byte[]> doScan(io.lettuce.core.ScanCursor cursor, ScanOptions options) {
ScanArgs scanArgs = connection.getScanArgs(options);
KeyScanCursor<byte[]> keyScanCursor = client.scan(cursor, scanArgs);
List<byte[]> keys = keyScanCursor.getKeys();
return new LettuceScanIteration<>(keyScanCursor, keys);
return new LettuceScanIteration<>(keyScanCursor, keyScanCursor.getKeys());
}
}.open();

View File

@@ -27,14 +27,14 @@ import org.springframework.lang.Nullable;
* across a Redis Cluster.
* <p/>
* The cursor state uses Lettuce's stateful {@link io.lettuce.core.ScanCursor} to keep track of scanning progress.
* Lettuce's cursor stores scanning progress inside its cursor so using a primitive {@code long} is not sufficient.
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 2.1
*/
abstract class LettuceScanCursor<T> extends ScanCursor<T> {
@Nullable private io.lettuce.core.ScanCursor state;
private @Nullable io.lettuce.core.ScanCursor state;
/**
* Creates a new {@link LettuceScanCursor} given {@link ScanOptions}.
@@ -93,19 +93,22 @@ abstract class LettuceScanCursor<T> extends ScanCursor<T> {
*
* @param cursor must not be {@literal null}.
* @param options must not be {@literal null}.
* @return
* @return never {@literal null}
*/
protected abstract LettuceScanIteration<T> doScan(io.lettuce.core.ScanCursor cursor, ScanOptions options);
/**
* Lettuce-specific extension to {@link ScanIteration} keeping track of the original
* {@link io.lettuce.core.ScanCursor} object.
*
* @author Mark Paluch
*/
static class LettuceScanIteration<T> extends ScanIteration<T> {
private final io.lettuce.core.ScanCursor cursor;
LettuceScanIteration(io.lettuce.core.ScanCursor cursor, Collection<T> items) {
super(Long.parseLong(cursor.getCursor()), items);
this.cursor = cursor;
}