com.github.tonivade.resp.command.CommandWrapper Maven / Gradle / Ivy
/*
* Copyright (c) 2015-2020, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.resp.command;
import static com.github.tonivade.resp.protocol.RedisToken.error;
import com.github.tonivade.resp.annotation.ParamLength;
import com.github.tonivade.resp.protocol.RedisToken;
public class CommandWrapper implements RespCommand {
private int params;
private final RespCommand command;
public CommandWrapper(RespCommand command) {
this.command = command;
ParamLength length = command.getClass().getAnnotation(ParamLength.class);
if (length != null) {
this.params = length.value();
}
}
@Override
public RedisToken execute(Request request) {
if (request.getLength() < params) {
return error("ERR wrong number of arguments for '" + request.getCommand() + "' command");
}
return command.execute(request);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy