Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
tishun committed Nov 15, 2024
1 parent 63ee6b9 commit e4d3ff1
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 86 deletions.
27 changes: 10 additions & 17 deletions src/main/java/io/lettuce/core/LcsArgs.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
/*
* Copyright 2011-2024 the original author or authors.
* Copyright 2011-Present, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed under the MIT License.
*/
package io.lettuce.core;

import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandKeyword;

/**
* Argument list builder for the Redis <a href="https://redis.io/commands/lcs">LCS</a> command. Static import the methods from
Expand All @@ -26,6 +18,7 @@
*
* @author Seonghwan Lee
* @since 6.6
* @see <a href="https://redis.io/commands/lcs">LCS command refference</a>
*/
public class LcsArgs implements CompositeArgument {

Expand Down Expand Up @@ -92,7 +85,7 @@ public LcsArgs withMatchLen() {
}

/**
* Request match position in each strings for results.
* Request match position in each string for results.
*
* @return {@code this} {@link LcsArgs}.
*/
Expand All @@ -118,19 +111,19 @@ public <K, V> void build(CommandArgs<K, V> args) {
args.add(key);
}
if (justLen) {
args.add("LEN");
args.add(CommandKeyword.LEN);
}
if (withIdx) {
args.add("IDX");
args.add(CommandKeyword.IDX);
}

if (minMatchLen > 0) {
args.add("MINMATCHLEN");
args.add(CommandKeyword.MINMATCHLEN);
args.add(minMatchLen);
}

if (withMatchLen) {
args.add("WITHMATCHLEN");
args.add(CommandKeyword.WITHMATCHLEN);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
* @author Mikhael Sokolov
* @author Tihomir Mateev
* @author Ali Takavci
* @author Seonghwan Lee
*/
@SuppressWarnings({ "unchecked", "varargs" })
class RedisCommandBuilder<K, V> extends BaseRedisCommandBuilder<K, V> {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/lettuce/core/StrAlgoArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
* {@link StrAlgoArgs} is a mutable object and instances should be used only once to avoid shared mutable state.
*
* @author dengliming
* @deprecated As of 6.6 in favor of {@link LcsArgs}
* @see <a href="https://redis.io/commands/lcs">LCS command refference</a>
* @since 6.0
*/
@Deprecated
public class StrAlgoArgs implements CompositeArgument {

private boolean justLen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ public interface RedisStringAsyncCommands<K, V> {
/**
* The STRALGO command implements complex algorithms that operate on strings. This method uses the LCS algorithm (longest
* common substring).
* <p>
* Command is no longer available in Redis server versions 7.0.x and later.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
Expand All @@ -423,6 +425,7 @@ public interface RedisStringAsyncCommands<K, V> {
*
* @param strAlgoArgs command arguments.
* @return StringMatchResult.
* @deprecated since 6.6 in favor of {@link #lcs(LcsArgs)}.
* @since 6.0
*/
@Deprecated
Expand All @@ -432,15 +435,16 @@ public interface RedisStringAsyncCommands<K, V> {
* The LCS command implements the longest common subsequence algorithm.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
* <li>Without modifiers, the string representing the longest common substring is returned.</li>
* <li>When {@link LcsArgs#justLen() LEN} is given the command returns the length of the longest common substring.</li>
* <li>When {@link LcsArgs#withIdx() IDX} is given the command returns an array with the LCS length and all the ranges in
* both the strings, start and end offset for each string, where there are matches. When {@link LcsArgs#withMatchLen()
* WITHMATCHLEN} is given each array representing a match will also have the length of the match.</li>
* </ul>
*
* @param lcsArgs command arguments.
* @return StringMatchResult.
* @param lcsArgs command arguments supplied by the {@link LcsArgs}.
* @return StringMatchResult
* @see <a href="https://redis.io/commands/lcs">LCS command refference</a>
* @since 6.6
*/
RedisFuture<StringMatchResult> lcs(LcsArgs lcsArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ public interface RedisStringReactiveCommands<K, V> {
/**
* The STRALGO command implements complex algorithms that operate on strings. This method uses the LCS algorithm (longest
* common substring).
* <p>
* Command is no longer available in Redis server versions 7.0.x and later.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
Expand All @@ -427,6 +429,7 @@ public interface RedisStringReactiveCommands<K, V> {
*
* @param strAlgoArgs command arguments.
* @return StringMatchResult.
* @deprecated since 6.6 in favor of {@link #lcs(LcsArgs)}.
* @since 6.0
*/
@Deprecated
Expand All @@ -436,15 +439,16 @@ public interface RedisStringReactiveCommands<K, V> {
* The LCS command implements the longest common subsequence algorithm.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
* <li>Without modifiers, the string representing the longest common substring is returned.</li>
* <li>When {@link LcsArgs#justLen() LEN} is given the command returns the length of the longest common substring.</li>
* <li>When {@link LcsArgs#withIdx() IDX} is given the command returns an array with the LCS length and all the ranges in
* both the strings, start and end offset for each string, where there are matches. When {@link LcsArgs#withMatchLen()
* WITHMATCHLEN} is given each array representing a match will also have the length of the match.</li>
* </ul>
*
* @param lcsArgs command arguments.
* @return StringMatchResult.
* @param lcsArgs command arguments supplied by the {@link LcsArgs}.
* @return StringMatchResult
* @see <a href="https://redis.io/commands/lcs">LCS command refference</a>
* @since 6.6
*/
Mono<StringMatchResult> lcs(LcsArgs lcsArgs);
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/io/lettuce/core/api/sync/RedisStringCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ public interface RedisStringCommands<K, V> {
/**
* The STRALGO command implements complex algorithms that operate on strings. This method uses the LCS algorithm (longest
* common substring).
* <p>
* Command is no longer available in Redis server versions 7.0.x and later.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
Expand All @@ -422,6 +424,7 @@ public interface RedisStringCommands<K, V> {
*
* @param strAlgoArgs command arguments.
* @return StringMatchResult.
* @deprecated since 6.6 in favor of {@link #lcs(LcsArgs)}.
* @since 6.0
*/
@Deprecated
Expand All @@ -431,15 +434,16 @@ public interface RedisStringCommands<K, V> {
* The LCS command implements the longest common subsequence algorithm.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
* <li>Without modifiers, the string representing the longest common substring is returned.</li>
* <li>When {@link LcsArgs#justLen() LEN} is given the command returns the length of the longest common substring.</li>
* <li>When {@link LcsArgs#withIdx() IDX} is given the command returns an array with the LCS length and all the ranges in
* both the strings, start and end offset for each string, where there are matches. When {@link LcsArgs#withMatchLen()
* WITHMATCHLEN} is given each array representing a match will also have the length of the match.</li>
* </ul>
*
* @param lcsArgs command arguments.
* @return StringMatchResult.
* @param lcsArgs command arguments supplied by the {@link LcsArgs}.
* @return StringMatchResult
* @see <a href="https://redis.io/commands/lcs">LCS command refference</a>
* @since 6.6
*/
StringMatchResult lcs(LcsArgs lcsArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ public interface NodeSelectionStringAsyncCommands<K, V> {
/**
* The STRALGO command implements complex algorithms that operate on strings. This method uses the LCS algorithm (longest
* common substring).
* <p>
* Command is no longer available in Redis server versions 7.0.x and later.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
Expand All @@ -422,23 +424,26 @@ public interface NodeSelectionStringAsyncCommands<K, V> {
*
* @param strAlgoArgs command arguments.
* @return StringMatchResult.
* @deprecated since 6.6 in favor of {@link #lcs(LcsArgs)}.
* @since 6.0
*/
@Deprecated
AsyncExecutions<StringMatchResult> stralgoLcs(StrAlgoArgs strAlgoArgs);

/**
* The LCS command implements the longest common subsequence algorithm.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
* <li>Without modifiers, the string representing the longest common substring is returned.</li>
* <li>When {@link LcsArgs#justLen() LEN} is given the command returns the length of the longest common substring.</li>
* <li>When {@link LcsArgs#withIdx() IDX} is given the command returns an array with the LCS length and all the ranges in
* both the strings, start and end offset for each string, where there are matches. When {@link LcsArgs#withMatchLen()
* WITHMATCHLEN} is given each array representing a match will also have the length of the match.</li>
* </ul>
*
* @param lcsArgs command arguments.
* @return StringMatchResult.
* @param lcsArgs command arguments supplied by the {@link LcsArgs}.
* @return StringMatchResult
* @see <a href="https://redis.io/commands/lcs">LCS command refference</a>
* @since 6.6
*/
AsyncExecutions<StringMatchResult> lcs(LcsArgs lcsArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ public interface NodeSelectionStringCommands<K, V> {
/**
* The STRALGO command implements complex algorithms that operate on strings. This method uses the LCS algorithm (longest
* common substring).
* <p>
* Command is no longer available in Redis server versions 7.0.x and later.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
Expand All @@ -422,23 +424,26 @@ public interface NodeSelectionStringCommands<K, V> {
*
* @param strAlgoArgs command arguments.
* @return StringMatchResult.
* @deprecated since 6.6 in favor of {@link #lcs(LcsArgs)}.
* @since 6.0
*/
@Deprecated
Executions<StringMatchResult> stralgoLcs(StrAlgoArgs strAlgoArgs);

/**
* The LCS command implements the longest common subsequence algorithm.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
* <li>Without modifiers, the string representing the longest common substring is returned.</li>
* <li>When {@link LcsArgs#justLen() LEN} is given the command returns the length of the longest common substring.</li>
* <li>When {@link LcsArgs#withIdx() IDX} is given the command returns an array with the LCS length and all the ranges in
* both the strings, start and end offset for each string, where there are matches. When {@link LcsArgs#withMatchLen()
* WITHMATCHLEN} is given each array representing a match will also have the length of the match.</li>
* </ul>
*
* @param lcsArgs command arguments.
* @return StringMatchResult.
* @param lcsArgs command arguments supplied by the {@link LcsArgs}.
* @return StringMatchResult
* @see <a href="https://redis.io/commands/lcs">LCS command refference</a>
* @since 6.6
*/
Executions<StringMatchResult> lcs(LcsArgs lcsArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.lettuce.core.StringMatchResult;
import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.protocol.CommandKeyword;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
Expand All @@ -38,7 +39,7 @@
*/
public class StringMatchResultOutput<K, V> extends CommandOutput<K, V, StringMatchResult> {

private static final ByteBuffer LEN = StandardCharsets.US_ASCII.encode("len");
private static final ByteBuffer LEN = StandardCharsets.US_ASCII.encode(CommandKeyword.LEN.toString().toLowerCase());

private String matchString;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/lettuce/core/protocol/CommandKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public enum CommandKeyword implements ProtocolKeyword {

BY, BYLEX, BYSCORE, CACHING, CAT, CH, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DELSLOTSRANGE, DELUSER, DESC, DRYRUN, SOFT, HARD, ENCODING,

FAILOVER, FORGET, FIELDS, FLAGS, FLUSH, FORCE, FREQ, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE, INFO,
FAILOVER, FORGET, FIELDS, FLAGS, FLUSH, FORCE, FREQ, FLUSHSLOTS, GENPASS, GETNAME, GETUSER, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE, IDX, INFO,

IDLETIME, JUSTID, KILL, KEYSLOT, LEFT, LEN, LIMIT, LINKS, LIST, LOAD, LOG, MATCH,

MAX, MAXLEN, MEET, MIN, MINID, MOVED, NO, NOACK, NOCOMMANDS, NODE, NODES, NOMKSTREAM, NOPASS, NOSAVE, NOT, NOVALUES, NUMSUB, SHARDCHANNELS, SHARDNUMSUB, NUMPAT, NX, OFF, ON, ONE, OR, PAUSE, PREFIXES,
MAX, MAXLEN, MEET, MIN, MINID, MINMATCHLEN, MOVED, NO, NOACK, NOCOMMANDS, NODE, NODES, NOMKSTREAM, NOPASS, NOSAVE, NOT, NOVALUES, NUMSUB, SHARDCHANNELS, SHARDNUMSUB, NUMPAT, NX, OFF, ON, ONE, OR, PAUSE, PREFIXES,

REFCOUNT, REMOVE, RELOAD, REPLACE, REDIRECT, REPLICATE, REPLICAS, REV, RESET, RESETCHANNELS, RESETKEYS, RESETPASS,

RESETSTAT, RESTART, RETRYCOUNT, REWRITE, RIGHT, SAVECONFIG, SDSLEN, SETINFO, SETNAME, SETSLOT, SHARDS, SLOTS, STABLE,

MIGRATING, IMPORTING, SAVE, SKIPME, SLAVES, STREAM, STORE, SUM, SEGFAULT, SETUSER, TAKEOVER, TRACKING, TRACKINGINFO, TYPE, UNBLOCK, USERS, USAGE, WEIGHTS, WHOAMI,

WITHSCORE, WITHSCORES, WITHVALUES, XOR, XX, YES, INDENT, NEWLINE, SPACE;
WITHMATCHLEN, WITHSCORE, WITHSCORES, WITHVALUES, XOR, XX, YES, INDENT, NEWLINE, SPACE;

public final byte[] bytes;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-Present, Redis Ltd. and Contributors
* Copyright 2017-Present, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
Expand Down Expand Up @@ -392,23 +392,22 @@ interface RedisStringCoroutinesCommands<K : Any, V : Any> {
suspend fun setrange(key: K, offset: Long, value: V): Long?

/**
* The STRALGO command implements complex algorithms that operate on strings. This method uses the LCS algorithm (longest
* common substring).
* The LCS command implements the longest common subsequence algorithm.
*
* <ul>
* <li>Without modifiers the string representing the longest common substring is returned.</li>
* <li>When [StrAlgoArgs#justLen LEN] is given the command returns the length of the longest common substring.</li>
* <li>When [StrAlgoArgs#withIdx IDX] is given the command returns an array with the LCS length and all the ranges
* in both the strings, start and end offset for each string, where there are matches. When
* [StrAlgoArgs#withMatchLen WITHMATCHLEN] is given each array representing a match will also have the length of the
* match.</li>
* <li>Without modifiers, the string representing the longest common substring is returned.</li>
* <li>When [LcsArgs#justLen LEN] is given the command returns the length of the longest common substring.</li>
* <li>When [LcsArgs#withIdx IDX] is given the command returns an array with the LCS length and all the ranges in
* both the strings, start and end offset for each string, where there are matches. When [LcsArgs#withMatchLen
* WITHMATCHLEN] is given each array representing a match will also have the length of the match.</li>
* </ul>
*
* @param strAlgoArgs command arguments.
* @return StringMatchResult.
* @since 6.0
* @param lcsArgs command arguments supplied by the [LcsArgs].
* @return StringMatchResult
* @see <a href="https://redis.io/commands/lcs">LCS command refference</a>
* @since 6.6
*/
suspend fun stralgoLcs(strAlgoArgs: StrAlgoArgs): StringMatchResult?
suspend fun lcs(lcsArgs: LcsArgs): StringMatchResult?

/**
* Get the length of the value stored in a key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal class RedisStringCoroutinesCommandsImpl<K : Any, V : Any>(internal val

override suspend fun setrange(key: K, offset: Long, value: V): Long? = ops.setrange(key, offset, value).awaitFirstOrNull()

override suspend fun stralgoLcs(strAlgoArgs: StrAlgoArgs): StringMatchResult? = ops.stralgoLcs(strAlgoArgs).awaitFirstOrNull()
override suspend fun lcs(lcsArgs: LcsArgs): StringMatchResult? = ops.lcs(lcsArgs).awaitFirstOrNull()

override suspend fun strlen(key: K): Long? = ops.strlen(key).awaitFirstOrNull()

Expand Down
Loading

0 comments on commit e4d3ff1

Please sign in to comment.