Skip to content

Commit

Permalink
Implement command (no arg) (#4026)
Browse files Browse the repository at this point in the history
* Implement  command (no arg)
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

* Update ControlCommandsTest.java

---------

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>
  • Loading branch information
ggivo and sazzad16 authored Nov 20, 2024
1 parent fcdc0d5 commit eb6cc47
Show file tree
Hide file tree
Showing 2 changed files with 28 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 @@ -501,6 +501,28 @@ public void commandGetKeys() {
assertEquals(2, keySandFlags.get(0).getValue().size());
}


@Test
public void commandNoArgs() {
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 eb6cc47

Please sign in to comment.