DATAREDIS-635 - Polishing.
Update Javadoc and format code a bit. Original Pull Request: #296
This commit is contained in:
@@ -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 -> {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user