Skip to content

Commit

Permalink
Add overload to ScanArgs to accept a binary match #1675
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Mar 22, 2021
1 parent 737a60f commit db44a48
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/main/java/io/lettuce/core/ScanArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public class ScanArgs implements CompositeArgument {

private Long count;

private String match;

private Charset charset;
private byte[] match;

/**
* Builder entry points for {@link ScanArgs}.
Expand Down Expand Up @@ -76,6 +74,18 @@ public static ScanArgs matches(String matches) {
return new ScanArgs().match(matches);
}

/**
* Creates new {@link ScanArgs} with {@literal MATCH} set.
*
* @param matches the filter.
* @return new {@link ScanArgs} with {@literal MATCH} set.
* @since 6.0.4
* @see ScanArgs#match(byte[])
*/
public static ScanArgs matches(byte[] matches) {
return new ScanArgs().match(matches);
}

}

/**
Expand All @@ -101,8 +111,23 @@ public ScanArgs match(String match, Charset charset) {
LettuceAssert.notNull(match, "Match must not be null");
LettuceAssert.notNull(charset, "Charset must not be null");

this.match = match;
this.charset = charset;
return match(match.getBytes(charset));
}

/**
* Set the match filter.
*
* @param match the filter, must not be {@code null}.
* @return {@literal this} {@link ScanArgs}.
* @since 6.0.4
*/
public ScanArgs match(byte[] match) {

LettuceAssert.notNull(match, "Match must not be null");

this.match = new byte[match.length];
System.arraycopy(match, 0, this.match, 0, match.length);

return this;
}

Expand All @@ -121,7 +146,7 @@ public ScanArgs limit(long count) {
public <K, V> void build(CommandArgs<K, V> args) {

if (match != null) {
args.add(MATCH).add(match.getBytes(charset));
args.add(MATCH).add(match);
}

if (count != null) {
Expand Down

0 comments on commit db44a48

Please sign in to comment.