Lettuce instrumentation - optimization to avoid extra toString() (#8984)
This commit is contained in:
parent
7379810603
commit
600c5873dd
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package io.lettuce.core.protocol;
|
package io.lettuce.core.protocol;
|
||||||
|
|
||||||
|
import io.lettuce.core.codec.StringCodec;
|
||||||
import io.lettuce.core.protocol.CommandArgs.KeyArgument;
|
import io.lettuce.core.protocol.CommandArgs.KeyArgument;
|
||||||
import io.lettuce.core.protocol.CommandArgs.SingularArgument;
|
import io.lettuce.core.protocol.CommandArgs.SingularArgument;
|
||||||
import io.lettuce.core.protocol.CommandArgs.ValueArgument;
|
import io.lettuce.core.protocol.CommandArgs.ValueArgument;
|
||||||
|
@ -22,19 +23,27 @@ public final class OtelCommandArgsUtil {
|
||||||
*/
|
*/
|
||||||
public static List<String> getCommandArgs(CommandArgs<?, ?> commandArgs) {
|
public static List<String> getCommandArgs(CommandArgs<?, ?> commandArgs) {
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
|
StringCodec stringCodec = new StringCodec();
|
||||||
|
|
||||||
for (SingularArgument argument : commandArgs.singularArguments) {
|
for (SingularArgument argument : commandArgs.singularArguments) {
|
||||||
String value = argument.toString();
|
String value = getArgValue(stringCodec, argument);
|
||||||
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);
|
result.add(value);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
|
private static String getArgValue(StringCodec stringCodec, SingularArgument argument) {
|
||||||
|
if (argument instanceof KeyArgument) {
|
||||||
|
KeyArgument keyArg = (KeyArgument) argument;
|
||||||
|
return stringCodec.decodeValue(keyArg.codec.encodeValue(keyArg.key));
|
||||||
|
}
|
||||||
|
if (argument instanceof ValueArgument) {
|
||||||
|
ValueArgument valueArg = (ValueArgument) argument;
|
||||||
|
return stringCodec.decodeValue(valueArg.codec.encodeValue(valueArg.val));
|
||||||
|
}
|
||||||
|
return argument.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private OtelCommandArgsUtil() {}
|
private OtelCommandArgsUtil() {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue