Switch from plain String to DataType for ScanOptions.
Move the type method from KeyScanOptionsBuilder to the ScanOptionsBuilder to allow removal of the former. Add a test for the reactive variant and allow SCAN tests with TYPE option to be executed starting with Redis 6.0. Original Pull Request: #2109
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.data.redis.core;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -24,6 +25,7 @@ import org.springframework.util.StringUtils;
|
||||
* Options to be used for with {@literal SCAN} commands.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 2.6
|
||||
*/
|
||||
public class KeyScanOptions extends ScanOptions {
|
||||
@@ -35,7 +37,7 @@ public class KeyScanOptions extends ScanOptions {
|
||||
|
||||
private final @Nullable String type;
|
||||
|
||||
private KeyScanOptions(@Nullable Long count, @Nullable String pattern, @Nullable byte[] bytePattern,
|
||||
KeyScanOptions(@Nullable Long count, @Nullable String pattern, @Nullable byte[] bytePattern,
|
||||
@Nullable String type) {
|
||||
|
||||
super(count, pattern, bytePattern);
|
||||
@@ -43,12 +45,13 @@ public class KeyScanOptions extends ScanOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Static factory method that returns a new {@link KeyScanOptionsBuilder}.
|
||||
* Static factory method that returns a new {@link ScanOptionsBuilder}.
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static KeyScanOptionsBuilder scanOptions() {
|
||||
return new KeyScanOptionsBuilder();
|
||||
public static ScanOptionsBuilder scanOptions(DataType type) {
|
||||
return new ScanOptionsBuilder().type(type);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -71,68 +74,4 @@ public class KeyScanOptions extends ScanOptions {
|
||||
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
public static class KeyScanOptionsBuilder extends ScanOptionsBuilder {
|
||||
|
||||
private @Nullable String type;
|
||||
|
||||
private KeyScanOptionsBuilder() {}
|
||||
|
||||
/**
|
||||
* Returns the current {@link KeyScanOptionsBuilder} configured with the given {@code count}.
|
||||
*
|
||||
* @param count
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public KeyScanOptionsBuilder count(long count) {
|
||||
super.count(count);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current {@link KeyScanOptionsBuilder} configured with the given {@code pattern}.
|
||||
*
|
||||
* @param pattern
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public KeyScanOptionsBuilder match(String pattern) {
|
||||
super.match(pattern);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current {@link KeyScanOptionsBuilder} configured with the given {@code pattern}.
|
||||
*
|
||||
* @param pattern
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public KeyScanOptionsBuilder match(byte[] pattern) {
|
||||
super.match(pattern);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current {@link KeyScanOptionsBuilder} configured with the given {@code type}.
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public KeyScanOptionsBuilder type(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a new {@link KeyScanOptions} objects.
|
||||
*
|
||||
* @return a new {@link KeyScanOptions} objects.
|
||||
*/
|
||||
@Override
|
||||
public KeyScanOptions build() {
|
||||
return new KeyScanOptions(count, pattern, bytePattern, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ package org.springframework.data.redis.core;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -41,6 +43,7 @@ public class ScanOptions {
|
||||
private final @Nullable byte[] bytePattern;
|
||||
|
||||
ScanOptions(@Nullable Long count, @Nullable String pattern, @Nullable byte[] bytePattern) {
|
||||
|
||||
this.count = count;
|
||||
this.pattern = pattern;
|
||||
this.bytePattern = bytePattern;
|
||||
@@ -110,6 +113,7 @@ public class ScanOptions {
|
||||
@Nullable Long count;
|
||||
@Nullable String pattern;
|
||||
@Nullable byte[] bytePattern;
|
||||
@Nullable DataType type;
|
||||
|
||||
ScanOptionsBuilder() {}
|
||||
|
||||
@@ -117,7 +121,7 @@ public class ScanOptions {
|
||||
* Returns the current {@link ScanOptionsBuilder} configured with the given {@code count}.
|
||||
*
|
||||
* @param count
|
||||
* @return
|
||||
* @return this.
|
||||
*/
|
||||
public ScanOptionsBuilder count(long count) {
|
||||
this.count = count;
|
||||
@@ -128,7 +132,7 @@ public class ScanOptions {
|
||||
* Returns the current {@link ScanOptionsBuilder} configured with the given {@code pattern}.
|
||||
*
|
||||
* @param pattern
|
||||
* @return
|
||||
* @return this.
|
||||
*/
|
||||
public ScanOptionsBuilder match(String pattern) {
|
||||
this.pattern = pattern;
|
||||
@@ -139,7 +143,7 @@ public class ScanOptions {
|
||||
* Returns the current {@link ScanOptionsBuilder} configured with the given {@code pattern}.
|
||||
*
|
||||
* @param pattern
|
||||
* @return
|
||||
* @return this.
|
||||
* @since 2.6
|
||||
*/
|
||||
public ScanOptionsBuilder match(byte[] pattern) {
|
||||
@@ -147,12 +151,46 @@ public class ScanOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current {@link ScanOptionsBuilder} configured with the given {@code type}. <br />
|
||||
* Please verify the the targeted command supports the
|
||||
* <a href="https://redis.io/commands/SCAN#the-type-option">TYPE</a> option before use.
|
||||
*
|
||||
* @param type must not be {@literal null}. Either do not set or use {@link DataType#NONE}.
|
||||
* @return this.
|
||||
* @since 2.6
|
||||
*/
|
||||
public ScanOptionsBuilder type(DataType type) {
|
||||
|
||||
Assert.notNull(type, "Type must not be null! Use NONE instead.");
|
||||
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current {@link ScanOptionsBuilder} configured with the given {@code type}.
|
||||
*
|
||||
* @param type the textual representation of {@link DataType#fromCode(String)}. Must not be {@literal null}.
|
||||
* @return this.
|
||||
* @throws IllegalArgumentException if given type is {@literal null} or unknown.
|
||||
*/
|
||||
public ScanOptionsBuilder type(String type) {
|
||||
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
return type(DataType.fromCode(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a new {@link ScanOptions} objects.
|
||||
*
|
||||
* @return a new {@link ScanOptions} objects.
|
||||
*/
|
||||
public ScanOptions build() {
|
||||
|
||||
if (type != null && !DataType.NONE.equals(type)) {
|
||||
return new KeyScanOptions(count, pattern, bytePattern, type.code());
|
||||
}
|
||||
return new ScanOptions(count, pattern, bytePattern);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user