use of io.lettuce.core.protocol.Command in project easeagent by megaease.
the class LettuceMetricInterceptorTest method getKey.
@Test
public void getKey() {
LettuceMetricInterceptor lettuceMetricInterceptor = new LettuceMetricInterceptor();
MethodInfo methodInfo = MethodInfo.builder().invoker("tttt").args(new Object[] { new Command(CommandKeyword.ADDR, null) }).build();
String key = lettuceMetricInterceptor.getKey(methodInfo, null);
assertEquals(CommandKeyword.ADDR.name(), key);
methodInfo = MethodInfo.builder().invoker("tttt").args(new Object[] { Arrays.asList(new Command(CommandKeyword.ADDR, null), new Command(CommandKeyword.ADDR, null)) }).build();
key = lettuceMetricInterceptor.getKey(methodInfo, null);
assertEquals("[" + CommandKeyword.ADDR.name() + "," + CommandKeyword.ADDR.name() + "]", key);
}
use of io.lettuce.core.protocol.Command in project lettuce-core by lettuce-io.
the class PubSubCommandHandlerUnitTests method shouldCompleteUnsubscribe.
@Test
void shouldCompleteUnsubscribe() throws Exception {
Command<String, String, String> subCmd = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>(StringCodec.UTF8), null);
Command<String, String, String> unSubCmd = new Command<>(CommandType.UNSUBSCRIBE, new PubSubOutput<>(StringCodec.UTF8), null);
doAnswer((Answer<PubSubEndpoint<String, String>>) inv -> {
PubSubOutput<String, String> out = inv.getArgument(0);
if (out.type() == PubSubOutput.Type.message) {
throw new NullPointerException("Expected exception");
}
return endpoint;
}).when(endpoint).notifyMessage(any());
sut.channelRegistered(context);
sut.channelActive(context);
stack.add(subCmd);
stack.add(unSubCmd);
ByteBuf buf = responseBytes("*3\r\n$9\r\nsubscribe\r\n$10\r\ntest_sub_0\r\n:1\r\n" + "*3\r\n$7\r\nmessage\r\n$10\r\ntest_sub_0\r\n$3\r\nabc\r\n" + "*3\r\n$11\r\nunsubscribe\r\n$10\r\ntest_sub_0\r\n:0\r\n");
sut.channelRead(context, buf);
sut.channelRead(context, responseBytes("*3\r\n$7\r\nmessage\r\n$10\r\ntest_sub_1\r\n$3\r\nabc\r\n"));
assertThat(unSubCmd.isDone()).isTrue();
}
use of io.lettuce.core.protocol.Command in project lettuce-core by lettuce-io.
the class CliParser method parse.
/**
* Parse a CLI command string into a {@link Command}.
*
* @param command
* @return
*/
public static Command<String, String, List<Object>> parse(String command) {
String[] parts = command.split(" ");
boolean quoted = false;
ProtocolKeyword type = null;
CommandArgs<String, String> args = new CommandArgs<>(StringCodec.UTF8);
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < parts.length; i++) {
String part = parts[i];
if (quoted && part.endsWith("\"")) {
buffer.append(part, 0, part.length() - 1);
} else if (part.startsWith("\"")) {
quoted = true;
buffer.append(buffer.append(part.substring(1)));
} else {
buffer.append(part);
}
if (quoted) {
continue;
}
if (type == null) {
String typeName = buffer.toString();
type = new ProtocolKeyword() {
@Override
public byte[] getBytes() {
return name().getBytes(StandardCharsets.UTF_8);
}
@Override
public String name() {
return typeName;
}
};
} else {
args.addKey(buffer.toString());
}
buffer.setLength(0);
}
return new Command<>(type, new ArrayOutput<>(StringCodec.UTF8), args);
}
use of io.lettuce.core.protocol.Command in project lettuce-core by lettuce-io.
the class RedisCommandBuilder method configGet.
Command<K, V, Map<String, String>> configGet(String... parameters) {
LettuceAssert.notNull(parameters, "Parameters " + MUST_NOT_BE_NULL);
LettuceAssert.notEmpty(parameters, "Parameters " + MUST_NOT_BE_EMPTY);
CommandArgs<String, String> args = new CommandArgs<>(StringCodec.UTF8).add(GET);
for (String parameter : parameters) {
args.add(parameter);
}
return Command.class.cast(new Command(CONFIG, new MapOutput<>(StringCodec.UTF8), args));
}
use of io.lettuce.core.protocol.Command in project lettuce-core by lettuce-io.
the class CustomCommandIntegrationTests method standaloneAsyncBatchTransaction.
@Test
void standaloneAsyncBatchTransaction() {
RedisCommand<String, String, String> multi = new Command<>(CommandType.MULTI, new StatusOutput<>(StringCodec.UTF8));
RedisCommand<String, String, String> set = new Command<>(CommandType.SET, new StatusOutput<>(StringCodec.UTF8), new CommandArgs<>(StringCodec.UTF8).addKey("key").add("value"));
RedisCommand<String, String, TransactionResult> exec = new Command<>(CommandType.EXEC, null);
AsyncCommand<String, String, String> async1 = new AsyncCommand<>(multi);
AsyncCommand<String, String, String> async2 = new AsyncCommand<>(set);
AsyncCommand<String, String, TransactionResult> async3 = new AsyncCommand<>(exec);
getStandaloneConnection().dispatch(Arrays.asList(async1, async2, async3));
assertThat(TestFutures.getOrTimeout(async1.toCompletableFuture())).isEqualTo("OK");
assertThat(TestFutures.getOrTimeout(async2.toCompletableFuture())).isEqualTo("OK");
TransactionResult transactionResult = TestFutures.getOrTimeout(async3.toCompletableFuture());
assertThat(transactionResult.wasDiscarded()).isFalse();
assertThat(transactionResult.<String>get(0)).isEqualTo("OK");
}
Aggregations