-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract query arguments without regex on lettuce 6 (#8932)
- Loading branch information
Showing
3 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ttuce/lettuce-5.1/library/src/main/java/io/lettuce/core/protocol/OtelCommandArgsUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.lettuce.core.protocol; | ||
|
||
import io.lettuce.core.protocol.CommandArgs.KeyArgument; | ||
import io.lettuce.core.protocol.CommandArgs.SingularArgument; | ||
import io.lettuce.core.protocol.CommandArgs.ValueArgument; | ||
import io.opentelemetry.instrumentation.lettuce.common.LettuceArgSplitter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
// Helper class for accessing package private fields in CommandArgs and its inner classes. | ||
// https://github.com/lettuce-io/lettuce-core/blob/main/src/main/java/io/lettuce/core/protocol/CommandArgs.java | ||
public final class OtelCommandArgsUtil { | ||
|
||
/** | ||
* Extract argument {@link List} from {@link CommandArgs} so that we wouldn't need to parse them | ||
* from command {@link String} with {@link LettuceArgSplitter#splitArgs}. | ||
*/ | ||
public static List<String> getCommandArgs(CommandArgs<?, ?> commandArgs) { | ||
List<String> result = new ArrayList<>(); | ||
for (SingularArgument argument : commandArgs.singularArguments) { | ||
String value = argument.toString(); | ||
if (argument instanceof KeyArgument && value.startsWith("key<") && value.endsWith(">")) { | ||
value = value.substring("key<".length(), value.length() - 1); | ||
} else if (argument instanceof ValueArgument | ||
&& value.startsWith("value<") | ||
&& value.endsWith(">")) { | ||
value = value.substring("value<".length(), value.length() - 1); | ||
} | ||
result.add(value); | ||
} | ||
return result; | ||
} | ||
|
||
private OtelCommandArgsUtil() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters