use of io.lettuce.core.protocol.CommandArgs 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.CommandArgs in project turms by turms-im.
the class TurmsRedisCommandBuilder method georadiusbymember.
// Geo
public <T> Command<ByteBuf, ByteBuf, List<GeoWithin<T>>> georadiusbymember(CommandType commandType, ByteBuf key, ByteBuf member, double distance, String unit, GeoArgs geoArgs) {
CommandArgs<ByteBuf, ByteBuf> args = new CommandArgs<>(memberCodec).addKey(key).addValue(member).add(distance).add(unit);
geoArgs.build(args);
GeoWithinListOutput output = new GeoWithinListOutput<>(memberCodec, geoArgs.isWithDistance(), geoArgs.isWithHash(), geoArgs.isWithCoordinates());
return createCommand(commandType, output, args);
}
use of io.lettuce.core.protocol.CommandArgs 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();
}
use of io.lettuce.core.protocol.CommandArgs in project lettuce-core by lettuce-io.
the class CommandSegmentCommandFactory method createCommand.
@Override
public RedisCommand<Object, Object, Object> createCommand(Object[] parameters) {
MethodParametersAccessor parametersAccessor = new CodecAwareMethodParametersAccessor(new DefaultMethodParametersAccessor(commandMethod.getParameters(), parameters), typeContext);
CommandArgs<Object, Object> args = new CommandArgs<>(redisCodec);
CommandOutput<Object, Object, ?> output = outputFactory.create(redisCodec);
Command<Object, Object, ?> command = new Command<>(this.segments.getCommandType(), output, args);
parameterBinder.bind(args, redisCodec, segments, parametersAccessor);
return (Command) command;
}
use of io.lettuce.core.protocol.CommandArgs in project lettuce-core by lettuce-io.
the class ParameterBinderUnitTests method bind.
private CommandArgs<String, String> bind(CommandMethod commandMethod, Object object) {
DefaultMethodParametersAccessor parametersAccessor = new DefaultMethodParametersAccessor(commandMethod.getParameters(), object);
CommandArgs<String, String> args = new CommandArgs<>(new StringCodec());
binder.bind(args, StringCodec.UTF8, segments, parametersAccessor);
return args;
}
Aggregations