use of io.lettuce.core.protocol.ProtocolKeyword 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.ProtocolKeyword in project uavstack by uavorg.
the class Lettuce5CommandHandlerIT method doWriteStart.
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object doWriteStart(Object[] args) {
RedisCommand cmdRc = (RedisCommand) args[0];
ProtocolKeyword cmd = (ProtocolKeyword) cmdRc.getType();
String host = (String) args[1];
Integer port = (Integer) args[2];
String targetURL = "redis://" + host + ":" + port;
String redisAction = cmd.toString();
if (logger.isDebugable()) {
logger.debug("REDIS INVOKE START: " + targetURL + " action: " + redisAction, null);
}
Map<String, Object> params = new HashMap<String, Object>();
params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, targetURL);
params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, redisAction);
params.put(CaptureConstants.INFO_CLIENT_APPID, appid);
params.put(CaptureConstants.INFO_CLIENT_TYPE, "redis.client.Lettuce");
// register adapter
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "registerAdapter", Lettuce5ClientAdapter.class);
ivcContextParams = (Map<String, Object>) UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap", InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.PRECAP, params, Lettuce5ClientAdapter.class, args);
UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT, Monitor.CapturePhase.PRECAP, params);
return null;
}
use of io.lettuce.core.protocol.ProtocolKeyword in project ballcat by ballcat-projects.
the class AbstractRedisModuleHelper method execute.
@SuppressWarnings("unchecked")
protected <T> Optional<T> execute(String key, ProtocolKeyword type, CommandOutput<byte[], byte[], T> output, String... args) {
List<byte[]> extraArgs = Arrays.stream(args).filter(StringUtils::hasLength).map(arg -> valueSerializer.serialize(arg)).collect(Collectors.toList());
CommandArgs<byte[], byte[]> commandArgs = new CommandArgs<>(codec).addKey(keySerializer.serialize(key)).addValues(extraArgs);
try (LettuceConnection connection = (LettuceConnection) connectionFactory.getConnection()) {
RedisFuture<T> future = connection.getNativeConnection().dispatch(type, output, commandArgs);
return Optional.ofNullable(future.get());
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
} catch (Exception e) {
log.error("[execute] 执行异常, KEY: [{}], type: [{}], args: [{}]", key, type.name(), args, e);
}
return Optional.empty();
}
Aggregations