Skip to content

Commit

Permalink
Implement command (no arg)
Browse files Browse the repository at this point in the history
https://redis.io/docs/latest/commands/command/

Adding it for completeness and as alternative to COMMAND INFO for Redis server prior 7.0.0.

COMMAND (no args) is available with Redis 2.x
COMMAND INFO is available since REDIS version 7.0.0

Relates to: #2922
Support COMMAND commands (#2922)
commit  : 3590438

Closes #793
  • Loading branch information
ggivo committed Nov 20, 2024
1 parent fcdc0d5 commit e2fd701
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -8253,6 +8253,12 @@ public Map<String, CommandInfo> commandInfo(String... commands) {
return CommandInfo.COMMAND_INFO_RESPONSE.build(connection.getOne());
}

public Map<String, CommandInfo> command() {
checkIsInMultiOrPipeline();
connection.sendCommand(COMMAND);
return CommandInfo.COMMAND_INFO_RESPONSE.build(connection.getOne());
}

public List<String> commandList() {
checkIsInMultiOrPipeline();
connection.sendCommand(COMMAND, LIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import com.google.gson.annotations.Since;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand Down Expand Up @@ -501,6 +502,28 @@ public void commandGetKeys() {
assertEquals(2, keySandFlags.get(0).getValue().size());
}


@Test
public void command() {
Map<String, CommandInfo> infos = jedis.command();

assertThat(infos.size(),greaterThan(0));

CommandInfo getInfo = infos.get("get");
assertEquals(2, getInfo.getArity());
assertEquals(2, getInfo.getFlags().size());
assertEquals(1, getInfo.getFirstKey());
assertEquals(1, getInfo.getLastKey());
assertEquals(1, getInfo.getStep());

assertNull(infos.get("foo")); // non-existing command

CommandInfo setInfo = infos.get("set");
assertEquals(3, setInfo.getAclCategories().size());
assertEquals(0, setInfo.getTips().size());
assertEquals(0, setInfo.getSubcommands().size());
}

@Test
public void commandInfo() {
Map<String, CommandInfo> infos = jedis.commandInfo("GET", "foo", "SET");
Expand Down

0 comments on commit e2fd701

Please sign in to comment.