Skip to content

Commit

Permalink
ISPN-14884 RESP MODULE LIST|LOAD|LOADEX|UNLOAD
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantarrant authored and jabolina committed May 19, 2023
1 parent 2c16371 commit 0135ed6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.infinispan.server.resp.commands.connection.COMMAND;
import org.infinispan.server.resp.commands.connection.ECHO;
import org.infinispan.server.resp.commands.connection.HELLO;
import org.infinispan.server.resp.commands.connection.MODULE;
import org.infinispan.server.resp.commands.connection.PING;
import org.infinispan.server.resp.commands.connection.QUIT;
import org.infinispan.server.resp.commands.connection.READONLY;
Expand Down Expand Up @@ -101,7 +102,7 @@ public String getName() {
indexedRespCommand[7] = new RespCommand[]{new HELLO()};
indexedRespCommand[8] = new RespCommand[]{new INCR(), new INCRBY(), new INCRBYFLOAT(), new INFO()};
indexedRespCommand[11] = new RespCommand[]{new LINDEX(), new LPUSH(), new LPUSHX()};
indexedRespCommand[12] = new RespCommand[]{new MGET(), new MSET()};
indexedRespCommand[12] = new RespCommand[]{new MGET(), new MSET(), new MODULE()};
indexedRespCommand[15] = new RespCommand[]{new PUBLISH(), new PING(), new PSUBSCRIBE(), new PUNSUBSCRIBE()};
indexedRespCommand[16] = new RespCommand[]{new QUIT()};
indexedRespCommand[17] = new RespCommand[]{new RPUSH(), new RPUSHX(), new RESET(), new READWRITE(), new READONLY()};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.infinispan.server.resp.commands.connection;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.CompletionStage;

import org.infinispan.security.AuthorizationPermission;
import org.infinispan.server.resp.ByteBufferUtils;
import org.infinispan.server.resp.Resp3Handler;
import org.infinispan.server.resp.RespCommand;
import org.infinispan.server.resp.RespRequestHandler;
import org.infinispan.server.resp.commands.Resp3Command;

import io.netty.channel.ChannelHandlerContext;

/**
* <a href="https://redis.io/commands/module-list/">MODULE LIST</a>
*
* @since 15.0
*/
public class MODULE extends RespCommand implements Resp3Command {
public MODULE() {
super(-1, 0, 0, 0);
}

@Override
public CompletionStage<RespRequestHandler> perform(Resp3Handler handler, ChannelHandlerContext ctx,
List<byte[]> arguments) {
handler.checkPermission(AuthorizationPermission.ADMIN);
String subcommand = new String(arguments.get(0), StandardCharsets.UTF_8).toUpperCase();
switch (subcommand) {
case "LIST":
ByteBufferUtils.stringToByteBuf("*0\r\n", handler.allocatorToUse());
break;
case "LOAD":
case "LOADEX":
case "UNLOAD":
ByteBufferUtils.stringToByteBuf("-ERR module loading/unloading unsupported\r\n", handler.allocatorToUse());
break;
}
return handler.myStage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.lettuce.core.SetArgs;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.codec.StringCodec;
import io.lettuce.core.output.ArrayOutput;
import io.lettuce.core.output.StatusOutput;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.ProtocolKeyword;
Expand Down Expand Up @@ -577,29 +578,9 @@ public void testStrlenNotPresent() {
public void testUpperLowercase() {
RedisCommands<String, String> redis = redisConnection.sync();
CommandArgs<String, String> args = new CommandArgs<>(StringCodec.UTF8).addValue("Hello");
String response = redis.dispatch(new ProtocolKeyword() {
@Override
public byte[] getBytes() {
return "ECHO".getBytes();
}

@Override
public String name() {
return "ECHO";
}
}, new StatusOutput<>(StringCodec.UTF8), args);
String response = redis.dispatch(new SimpleCommand("ECHO"), new StatusOutput<>(StringCodec.UTF8), args);
assertEquals("Hello", response);
response = redis.dispatch(new ProtocolKeyword() {
@Override
public byte[] getBytes() {
return "echo".getBytes();
}

@Override
public String name() {
return "echo";
}
}, new StatusOutput<>(StringCodec.UTF8), args);
response = redis.dispatch(new SimpleCommand("echo"), new StatusOutput<>(StringCodec.UTF8), args);
assertEquals("Hello", response);
}

Expand All @@ -616,4 +597,31 @@ public void testInfo() {
assertThat(info).contains("# Server");
assertThat(info).doesNotContain("# Client");
}

@Test
public void testModule() {
RedisCommands<String, String> redis = redisConnection.sync();
CommandArgs<String, String> args = new CommandArgs<>(StringCodec.UTF8).addValue("LIST");
List<Object> response = redis.dispatch(new SimpleCommand("MODULE"), new ArrayOutput<>(StringCodec.UTF8), args);
assertEquals(0, response.size());
}

public static class SimpleCommand implements ProtocolKeyword {
private final String name;


public SimpleCommand(String name) {
this.name = name;
}

@Override
public byte[] getBytes() {
return name.getBytes(StandardCharsets.UTF_8);
}

@Override
public String name() {
return name;
}
}
}

0 comments on commit 0135ed6

Please sign in to comment.