[Plugin] [Redis] Fixed command multiple parameters (#196)

This commit is contained in:
qianmoQ 2023-01-29 17:10:56 +08:00 committed by GitHub
commit 3f6763406a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View File

@ -18,7 +18,7 @@ import java.util.Date;
import java.util.List;
@Slf4j
@SuppressFBWarnings(value = {"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"},
@SuppressFBWarnings(value = {"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "REC_CATCH_EXCEPTION"},
justification = "I prefer to suppress these FindBugs warnings")
public class RedisAdapter
extends NativeAdapter
@ -43,12 +43,20 @@ public class RedisAdapter
List<String> types = new ArrayList<>();
List<Object> columns = new ArrayList<>();
try {
String[] commands = content.split(" ", 2);
String[] commands = content.split(" ");
Protocol.Command cmd = Protocol.Command.valueOf(commands[0].toUpperCase());
Method method = MethodUtils.getMatchingMethod(Client.class, "sendCommand", Protocol.Command.class, String[].class);
method.setAccessible(true);
Client client = this.redisConnection.getJedis().getClient();
method.invoke(client, cmd, new String[] {commands[1]});
List<String> cmdParam = new ArrayList<>();
for (int i = 0; i < commands.length; i++) {
if (i == 0) {
continue;
}
cmdParam.add(commands[i]);
}
String[] cmdParamArr = cmdParam.toArray(new String[]{});
method.invoke(client, cmd, cmdParamArr);
Object body = client.getOne();
headers.add(commands[1]);
types.add("String");

View File

@ -2,15 +2,15 @@ package io.edurt.datacap.plugin.natived.redis;
import io.edurt.datacap.spi.adapter.Adapter;
import org.junit.Test;
import io.edurt.datacap.spi.model.Response;
public class RedisAdapterTest
extends RedisBaseTest
{
extends RedisBaseTest {
@Test
public void handlerExecute()
{
public void handlerExecute() {
RedisConnection connection = new RedisConnection(this.configure, this.response);
Adapter adapter = new RedisAdapter(connection);
adapter.handlerExecute("GET key");
Response cc = adapter.handlerExecute("keys asd");
System.out.println(cc);
}
}