Skip to content

Support INFO command in UnifiedJedis (simplified) #4079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public final CommandObject<String> configSet(String parameter, String value) {
return new CommandObject<>(commandArguments(Command.CONFIG).add(Keyword.SET).add(parameter).add(value), BuilderFactory.STRING);
}

private final CommandObject<String> INFO_COMMAND_OBJECT = new CommandObject<>(commandArguments(Command.INFO), BuilderFactory.STRING);

public final CommandObject<String> info() {
return INFO_COMMAND_OBJECT;
}

public final CommandObject<String> info(String section) {
return new CommandObject<>(commandArguments(Command.INFO).add(section), BuilderFactory.STRING);
}

// Key commands
public final CommandObject<Boolean> exists(String key) {
return new CommandObject<>(commandArguments(Command.EXISTS).key(key), BuilderFactory.BOOLEAN);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ public Connection getConnectionFromSlot(int slot) {
}

// commands
@Override
public String info() {
throw new UnsupportedOperationException("INFO command is not supported from JedisCluster.");
}

@Override
public String info(String section) {
throw new UnsupportedOperationException("INFO command is not supported from JedisCluster.");
}

public long spublish(String channel, String message) {
return executeCommand(commandObjects.spublish(channel, message));
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ public String configSet(String parameter, String value) {
return checkAndBroadcastCommand(commandObjects.configSet(parameter, value));
}

public String info() {
return executeCommand(commandObjects.info());
}

public String info(String section) {
return executeCommand(commandObjects.info(section));
}

// Key commands
@Override
public boolean exists(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;

import java.util.ArrayList;
Expand Down Expand Up @@ -128,6 +129,13 @@ public void pingBroadcast() {
assertEquals("PONG", cluster.ping());
}

@Test
public void info() {
assertThrows(UnsupportedOperationException.class, () -> cluster.info());

assertThrows(UnsupportedOperationException.class, () -> cluster.info("server"));
}

@Test
public void flushAllBroadcast() {
assertNull(cluster.get("foo"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package redis.clients.jedis.commands.unified.pooled;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
Expand All @@ -9,6 +10,7 @@
import java.util.List;

import io.redis.test.annotations.SinceRedisVersion;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -164,4 +166,13 @@ public void broadcastWithError() {
() -> jedis.functionDelete("xyz"));
assertEquals("ERR Library not found", error.getMessage());
}

@Test
public void info() {
String info = jedis.info();
assertThat(info, Matchers.notNullValue());

info = jedis.info("server");
assertThat(info, Matchers.notNullValue());
}
}
Loading